I have a component who receive props:
The data recived printed on console.log
How to extract the array from this object?
Before I send the array to my component look like this:
I have a component who receive props:
The data recived printed on console.log
How to extract the array from this object?
Before I send the array to my component look like this:
If you are doing
console.log(props);
you can get the array with:
const arr = props.data;
or
const { data } = props;
It sounds like you have a React component that is receive data like this:
<MyComponent data={myArray} />
If so, then inside that component, it will receive it on the prop named 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>
}