[英]Extract array from object?
If you are doing如果你正在做
console.log(props);
you can get the array with:你可以得到数组:
const arr = props.data;
or或者
const { data } = props;
I have finally used the function map() to resolve this issue.我终于用 function map() 解决了这个问题。
It sounds like you have a React component that is receive data like this:听起来您有一个接收数据的 React 组件,如下所示:
<MyComponent data={myArray} />
If so, then inside that component, it will receive it on the prop named data
.如果是这样,那么在该组件内部,它将在名为
data
的道具上接收它。
function MyComponent(props) {
console.log(props.data)
return <p>{data}</p>
}
Or written with the more common destructuring assignment:或者用更常见的解构赋值编写:
function MyComponent({data}) {
console.log(data)
return <p>{data}</p>
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.