我有这样的自定义组件
const MyCustomComponent = ({ value, style }) => {
// I can access value & style with value and style
return <View style={style}>
<Text>{value}</Text>
</View>
}
我可以这样称呼它
<MyCustomComponent value="123" style={{ color: "blue" }} />
我的问题是如何获取参数或alyelse,以将所有道具传递给我的组件?
在本机函数中,我可以使用arguments
获取allProps作为数组并将其设置为新变量,例如const allProps = arguments[0]
箭头功能怎么样?
您可以使用:
const MyCustomComponent = (props) => {
// I can access value & style with value and style
return <View style={props.style}>
<Text>{props.value}</Text>
</View>
}
const MyComponent({value, style})
分解了prop对象,仅提取了两个变量。您应该这样做: