我正在尝试在道具中添加阵列和功能,但是我似乎使用了错误的方法
<Component
property={{functionName, array}}
</Component>
const array = {
id: 1234,
name: 'John Doe'
address: 'Address'
}
我不确定是否应该以这种方式使用propproperty={{functionName,array}}
,因为array现在位于Object内部。
最好的选择(但这是个人的)是
const myExampleFuction = ()=>{};
const myExampleArray = {a:1,b:2};
const myProps ={myExampleFunction,myExampleArray};
return <Component {...myProps} />;
理论上说是正确的,但我确信可以用一种更简单/优雅的方式来完成。 你想要得到什么?