I'm new to react I need to pass array to another component via props but i got an issue
in Component1
this.state={
data:[], //some values inside both it
col:[]
}
<Component2 data={[...this.state.data]} col={[...this.state.col]}/>
in Component2
constructor(props){
super(props)
this.state = {
data:[...this.props.data],
col:[...this.props.col],
}
console.log(this.state.data+' inside state')
}
when I console.log i get the below output
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object] inside state
one of my array has 17 elements but why am not getting the actual data?is there any syntax error in my code?
one of my array has 17 elements but why am not getting the actual data?What do you mean, your question shows it logs the data. Maybe try:console.log(this.state.data,' inside state')`. I'm also not sure why you want copy data that is passed to Component2 to local state and why you make a shallow copy of the data twice.