I want to have a data structure in terms of array e.g.
data[0]
title:"ABC"
photo: "./123.jpg"
summ: "text text test"
data[1]
title:"ABCD"
photo: "./1234.jpg"
summ: "text texwt test"
I have attempted to setState like this, but it won't work. Please guide me ;(
this.setState({
data:{
title: [ ...this.state.data.title, title ],
photo: [ ...this.state.data.photo, photo ],
summ: [ ...this.state.data.summ, summ ]
}
});
Uncaught (in promise) TypeError: _this.state.data.concat is not a function
///// Mistake on not initialize my state
// this is incorrect
this.state={
data:{
title:null,
photo:null,
summ:null,
}
//The correct version is
this.state={
data:[],

it won't work?this.setState({data: [...this.state.data, {title, photo, summ}]})setState, you are assigning data to an object