I have been using React state to maintain some data. For ints and strings it's working well, but unfortunately arrays are not working.
In my component constructor, I have
constructor(props) {
super(props);
this.state = {
terms: 5,
myArray: []
}
and then, I am trying to maintain it in componentDidUpdate
componentDidUpdate() {
this.state = {
terms: this.state.terms,
myArray: this.state.myArray
}
but myArray: this.state.myArray is not working. However terms: this.state.terms is working perfectly.
Can someone help!