question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dangerouslySetInnerHTML doesn't work on SVG tag

See original GitHub issue

Hey @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:closed
  • Created 7 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
developitcommented, May 7, 2016

Ah okay so this is sort of a dupe of developit/preact-svg#15. On my to-do list!

0reactions
fdaciukcommented, May 7, 2016

Very nice! 😍 I’ll waiting for it =)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found