我将 Person 作为 props 传递给 React 组件。我知道 Persons 是一个对象数组,其中每个对象都有四个字段:
1) Name :(type string) 2) Surname :(type string) 3) Age :(type int) 4) Address :(type string)
type Props = {
Persons: Array<Object>,
}
因为我知道对象的字段,所以使用 Array<Object>,
传递不是一个好主意(不是描述性的)。有什么方法可以将此信息作为 props 传递吗?
最佳答案
是的,你可以这样做:
type Props = {
Persons: Array<{
name: string,
surname: string,
age: number,
address: string
}>
}
关于javascript - 如何在 react 中传递具有已知字段的对象作为 Prop ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45045033/