dangerouslySetInnerHTML doesn't work on SVG tag
See original GitHub issueHey @developit!
This property should work on svg tags, isn’t?
I’m trying to use it to generate SVG sprites:
const SvgIcon = ({ id, label }) => {
const props = {
className: 'icon',
'aria-hidden': true,
'aria-label': label,
dangerouslySetInnerHTML: {
__html: `<use xlink:href="/svg/icons.svg#${id}" />`
}
}
return <svg {...props} />
}
But use
tag is not being inserted inside of svg
😦
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
How do I use an SVG in React without using ... - Stack Overflow
Unfortunately it doesn't work unless I use dangerouslySetInnerHTML , so the icon shows up - however it appears broken. You can use the...
Read more >SVG tag -- creating SVG content on the fly - ReScript Forum
Suppose I've got a string like let s = "<svg height=\"1000\" width=\"1000\"> ... Is there some way to make this (or something like...
Read more >Using dangerouslySetInnerHTML - Getting Started with DOM
This article will discuss dangerouslySetInnerHTML in React and how it works, when to use it, and how you can apply it safely in...
Read more >How to use SVGs in React | Sanity.io guide
This article will explore how to use SVG in React in three examples.
Read more >preact dangerouslysetinnerhtml - You.com | The AI Search ...
This will only work for normal HTML - not React Components written in JSX! ... preactjs/preactdangerouslySetInnerHTML doesn't work on SVG tag#141.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ah okay so this is sort of a dupe of developit/preact-svg#15. On my to-do list!
Very nice! 😍 I’ll waiting for it =)