TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Transform SVG into React components

94 pointsby BafSover 7 years ago

8 comments

iamleppertover 7 years ago
This is doing little more than providing a wrapper around svgo, which is doing all the real work.<p>This is generally a poor use of SVG as well, if your use of SVG is for static assets, don&#x27;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.
评论 #15583941 未加载
评论 #15584997 未加载
评论 #15585098 未加载
评论 #15585281 未加载
debaserab2over 7 years ago
Let&#x27;s not forget, sometimes when you need some really basic functionality, you don&#x27;t <i>have</i> 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:<p><a href="https:&#x2F;&#x2F;gist.github.com&#x2F;ajbdev&#x2F;8d15e302564fe04a7d383c1a54f8d97d" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;ajbdev&#x2F;8d15e302564fe04a7d383c1a54f8d...</a><p>Despite it&#x27;s simplicity, it has yet to fail me.
评论 #15583460 未加载
评论 #15586936 未加载
askmikeover 7 years ago
This does exactly what I have been doing manually for at least ~15 times in the last week. If only I saw this a few weeks ago.. (It&#x27;s easy &#x2F; not lot of work, but why if we can automate?)
photoniosover 7 years ago
Doesn&#x27;t `react-svg-loader`[0] do the same?<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;boopathi&#x2F;react-svg-loader" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;boopathi&#x2F;react-svg-loader</a>
评论 #15583648 未加载
leeoniyaover 7 years ago
&quot;Your scientists were so preoccupied with whether or not they could, they didn’t stop to think if they should.&quot;
gjjonesover 7 years ago
Super cool to see other people using this pattern! People here are bringing up great points about the implications of this pattern. Our motivation to use this pattern was when replacing grunticon generating multiple colors of our SVGs during a build step. The grunticon step added a 1min+ to the feedback loop on seeing CSS changes(could have fixed this directly, lots of missed details in this story).<p>This simple script allowed us to quickly move past the problem during a rewrite to React, and solve more correctly when that system was a priority. <a href="https:&#x2F;&#x2F;gitlab.com&#x2F;gjjones&#x2F;svg-to-react" rel="nofollow">https:&#x2F;&#x2F;gitlab.com&#x2F;gjjones&#x2F;svg-to-react</a>
josteinkover 7 years ago
If I can have only one question, it would no doubt be “why”?
评论 #15583446 未加载
评论 #15583920 未加载
peterchauover 7 years ago
Amazing.
评论 #15583300 未加载