score:1

setstate accepts objects, plain and simple. if you call this.setstate(['a','b']) it will convert your array to an array-like object. why? because react allows that elsewhere in your code you should be able to call this.setstate({data: 'something'}) without having that fail. for reference this.state would now look like this:

{
  0: 'a',
  1: 'b',
  data: 'something'
}

why did you get a warning? because react performed this conversion, from array to array-like object, behind the scenes, and wants to let you know that things have changed. for example, after setting state to an array, you won't be able to call this.state.map ... or any other array methods.

if you need to store an array in state, set it to an object property: this.setstate({arraydata: ['a', 'b']}). in general it's a good practice to wrap your data in object properties, because you will certainly be lifting state up as you develop your application.


Related Query

More Query from same tag