Live data from Hacker News

Transform SVG into React components

github.com

1–10 of 35 posts

Re: Transform SVG into React components

#4
Let's not forget, sometimes when you need some really basic functionality, you don't have to reach for a module that maybe does a lot more than what you need. For example, the last time I needed svg inlined into a web app I was working on, this is the quick component that I whipped up:

https://gist.github.com/ajbdev/8d15e302564fe04a7d383c1a54f8d...

Despite it's simplicity, it has yet to fail me.

Re: Transform SVG into React components

#7
This is doing little more than providing a wrapper around svgo, which is doing all the real work.

This is generally a poor use of SVG as well, if your use of SVG is for static assets, don't transform all your SVG into react, leave it as SVG where it can be easily manipulated and editing by the plethora of tools that can work directly with SVG, previewed in the browser, etc. If you need you can inline the SVG into your CSS via a base64 URI, etc.

Re: Transform SVG into React components

#10
post #9

If I can have only one question, it would no doubt be “why”?

We do this at my work - it allows easy programmatic inclusion.

We wouldn’t do it if browsers weren’t a buggy mess with the USE tag though (Chrome in particular is a dumpster fire of SVG bugs).

Post reply on HN