Categories
Development

React add array to state array

I am new to React. In my state, I am trying to have an empty array initialized to store polygons.

The structure I want to have is an array like this.state.polyList = [[dot1,dot2,dot3...],[dot1,dot2,dot3...]]

I am trying to have a

let newState = Object.assign({},this.state);
let newValue = [points]; // "points" is [dot1,dot2,dot3...]
console.log(newValue[0][0]); // able to print correctly
newState.polyList = newState.polyList.concat(newValue)
this.setState(newState)

However, when I later log the state.polyList, I only have a few empty array ([]) inside list

Leave a Reply

Your email address will not be published. Required fields are marked *