TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Show HN: SVG-to-React – convert your SVG assets into accessible React components

4 点作者 TheSisb2超过 5 年前

1 comment

TheSisb2超过 5 年前
Hey HN! I&#x27;m really happy to be sharing this with you all today. I&#x27;ve been working on React projects for about 4 years now and I&#x27;ve always found that SVGs (whether icons or full illustrations) are best represented in my projects as individual React components. Some of the benefits are that:<p>- It&#x27;s easier to control your SVGs with clearly defined props<p>- You can bake in accessibility into your illustrations<p>- Unlike to icon fonts which load the entire font, you can leverage modern module loading practices to only load the SVGs you need (i.e.: import HackerNewsIcon from &#x27;...&#x27;)<p>- Unlike in-lining SVGs, the resource can be cached, bundled, and re-used multiple times without duplicating the contents.<p>- This tool automatically strips away `id`s so you don&#x27;t have id collisions.<p>- Since it&#x27;s a component, you can modify it to, for example, show a different SVG under a different locale if the English design doesn&#x27;t translate well.<p>This has helped our little design system team off-load the incoming requests to add new icons back out to the requesting teams. And if an icon doesn&#x27;t meet the requirements of our system, consumers can continue to use them in their own projects while still being aligned on props and a11y.<p>Hope you all find this useful too!