Created
August 12, 2021 22:57
-
-
Save mauriciomassaia/f39cd89cdebb24e1c9b65a0155ec204c to your computer and use it in GitHub Desktop.
Load SVG with Fetch + typescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const parser = new DOMParser() | |
export const loadSVG = async (path: string): Promise<HTMLElement> => { | |
const response = await fetch(path) | |
const data = await response.text() | |
const svg = parser.parseFromString(data, 'image/svg+xml') | |
return svg.documentElement | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment