【发布时间】:2021-12-09 12:29:16
【问题描述】:
我正在构建一个按钮组件:
interface ButtonProps {
startIcon?: ... <-- what type?
}
const Button = ({startIcon: StartIcon}) => {
return <button>{StartIcon && <StartIcon/>}</button>
}
// usage
<Button startIcon={SomeIcon}/>
我正在使用react-icons 库,我应该在接口中声明什么类型?如果我将 svg 元素作为 startIcon 属性传递,它对类型声明有影响吗?
【问题讨论】:
-
我相信 react-icons 提供了一个
IconType类型,可以在这里解决问题
标签: reactjs typescript svg react-icons