使用打字稿键入功能组件反应

时间:2021-01-24 12:54:59

标签: reactjs typescript

我想改变这个匿名。功能

const Button: React.FunctionComponent = ({ children }: Props) => { })

函数签名

function Button() { }

但是如何在函数版本上插入类型 React.FunctionComponent

1 个答案:

答案 0 :(得分:1)

你可以这样写:

interface DummyProps{
property1:string //here instead of property1 you can name it whatever you want to and its type can be anything.For example i have used here string
}

export default ({property1}:DummyProps) => {
return (
       <div>
           {property1}
       </div>
   );
}