【发布时间】:2020-12-09 07:04:31
【问题描述】:
所以我看到人们使用不同的方式来声明一个函数。但是,我看到了一种我不太理解的方式。示例代码如下:
type Props = {
name: string,
age: number
}
const someFunction = ({
name,
age
}: Props) => {
return (
// Do something here
)
}
所以我知道这里的代码首先是创建一个带有名称和年龄的 Props 对象。我没有得到的部分是它显示({name, age}: Props) 的部分。我猜这是一个将状态映射到道具的参数,但我不确定。谁能解释一下?
【问题讨论】:
标签: reactjs typescript react-props react-state react-functional-component