小编mai*_*mas的帖子

在React JS中渲染SVGSVGElement而不使用dangerouslySetInnerHtml

问题: 我可以SVGSVGElement在不使用的情况下渲染React dangerouslySetInnerHtml吗?

语境:

我使用的是vis.js图库,该getLegend方法返回一个SVGSVGElement对象,即 const icon = chart.getLegend(args); 在控制台中我可以看到:

in: icon instanceof SVGSVGElement
out: true
in: icon
out: <svg><rect x="0" y="0" width="30" height="30" class="vis-outline"></rect><path class="vis-graph-group0" d="M0,15 L30,15"></path></svg>
Run Code Online (Sandbox Code Playgroud)

问题:

当我尝试使用以下方法渲染时:

render (
<div> { icon } </div>
)
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Error: Objects are not valid as a React child (found: [object SVGSVGElement]). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from …
Run Code Online (Sandbox Code Playgroud)

javascript svg reactjs vis.js

6
推荐指数
1
解决办法
605
查看次数

标签 统计

javascript ×1

reactjs ×1

svg ×1

vis.js ×1