Answer the question
In order to leave comments, you need to log in
How to restructure props data and use it in state?
I'll show you with an example.
A props.bar
two-dimensional array was passed to .
To use it in a component, each subarray needs to be "flipped" ( ) I planned to solve this problem as follows:[ [1], [1, 2], [1, 2, 3] ]
state
.reverse()
class Foo extends Component {
constructor(props) {
super(props)
this.state = {
bar: this.restruct( props.bar )
}
}
render() {
console.log(this.state.bar)
return( <div></div> )
}
restruct(data) {
return data.map( arr => arr.reverse() )
}
}
Answer the question
In order to leave comments, you need to log in
Until I wrote it reverse
manually, nothing worked, I don’t know why this happened.
If you know - write ideas.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question