Is there any more efficent way other than using dangerouslySetInnerHTML to set svg string?
See original GitHub issueWhen I’m parsing markdown text, I will have a string whose content is a svg file, such as
<svg height="100" width="100">
<circle
cx="50" cy="50" r="40"
stroke="black" stroke-width="3" fill="red" />
</svg>
As far as now, it seems that the only way to render this svg string is to use dangerouslySetInnerHTML, I wanna to ask:
- Will this way inefficent?
- Is there any more efficent way in React?
Thanks for reading this issue. Looking forward your awesome answers.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (2 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 >DOM Elements - React
React implements a browser-independent DOM system for performance and ... to use units other than “px”, specify the value as a string with...
Read more >Using dangerouslySetInnerHTML - Getting Started with DOM
Yes, dangerouslySetInnerHTML is a property and requires only a HTML element to render. 2. Is it OK to use dangerouslySetInnerHTML? Yes, it will ......
Read more >SVG tag -- creating SVG content on the fly - ReScript Forum
If you have a string that you want to render as HTML, then dangerouslySetInnerHTML is the only way to do that in React....
Read more >Let's talk about SVG - Medium
Loading an external SVG as a React Element · 1. Avoid using dangerouslySetInnerHTML · 2. Convert the SVG text to individual react elements...
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 Free
Top 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

Shipping HTML parser to the client just to parse a pre-generated SVG seems excessive and would create a performance issue — unless you do it at compile time.
There are no performance problems with doing this. But be careful to make sure the HTML string is coming from a trusted source since otherwise it will create a security issue.