我正在使用带有“ @fluentui/react-northstar ”库的图标组件,如下所示
import { QnaIcon } from '@fluentui/react-northstar'
const Example1 = () => (
<>
<QnaIcon size="large" />
</>
)
现在我必须在图标名称来自类似这样的道具时动态加载图标组件
import React from 'react'
import { Button, TeamCreateIcon } from '@fluentui/react-northstar'
const Example2 = ({iconName}) => {
const MyIcon = <iconName /> ; //here I need to convert string to component
return (
<div >
<Button icon={<TeamCreateIcon />} title="Create" />
// Here I need set it
<Button icon={<MyIcon />} title="Create" />
</div>
)}
<Example2 iconName='QnaIcon' />