提问者:小点点

在组件道具中使用数组和函数


我正在尝试在道具中添加阵列和功能,但是我似乎使用了错误的方法

<Component
  property={{functionName, array}}
</Component>
const array = { 
  id: 1234,
  name: 'John Doe'
  address: 'Address'
}

我不确定是否应该以这种方式使用propproperty={{functionName,array}},因为array现在位于Object内部。


共2个答案

匿名用户

最好的选择(但这是个人的)是

const myExampleFuction = ()=>{};
const myExampleArray = {a:1,b:2};
const myProps ={myExampleFunction,myExampleArray};

return <Component {...myProps} />;
   

匿名用户

理论上说是正确的,但我确信可以用一种更简单/优雅的方式来完成。 你想要得到什么?