javascript - Parse SVG file to React component
问题描述
I have an SVG file: check.svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 28.3 28.3"><path d="M25.2 3.638l-1.6 1.6c-4.3 4.3-8.9 9.2-13.2 13.6l-5.9-4.9-1.7-1.4-2.8 3.3 1.7 1.4 7.5 6.2 1.6 1.3 1.4-1.4c4.8-4.8 9.9-10.4 14.6-15l1.6-1.6-3.2-3.1z"/></svg>
I want a React component from it; but I don't want any wrapper tag, just
<svg>
<path […]/>
</svg>
I know I can do something like
const renderSvg = svg => React.createElement('svg', {
dangerouslySetInnerHTML: { __html: svg }
});
or even easier
const RenderSvg = (svg) => <svg dangerouslySetInnerHTML={{ __html: svg }} />;
But I would end up with:
<svg>
<svg>
<path […]/>
</svg>
</svg>
Does anyone know how to achieve this without using an external library?
解决方案
推荐阅读
- formsflow.ai - 使用工作流“电子邮件通知”创建的表单
- java - 带有传统 Java 的 keycloak:一个简单的 api 示例?
- arrays - Ruby 中的数组解构
- python - 气流任务状态失败,“重试”参数> 0
- javascript - 我创建了随机密码生成器。它接受数字并打印该长度的随机密码。它在控制台上打印密码但被刷新
- c# - 事件侦听器不适用于 firebase 查询
- java - Spring Boot 中的邮件发送异常
- xamarin.forms - Xamarin Forms Prism (DialogService) with Switch in ListView items - EventToCommandBehaviour 触发多次
- reactjs - 如何打破 MUIDataTable 列单元格内容
- python - 如何在硒(python)中关闭标签广告