I have a handleClick() function which updates the state of a component.
handleClick = () => {
let temp_map = new Map();
temp_map.set('left', null);
temp_map.set('bottom',null);
temp_map.set('right', null);
temp_map.set('top', null);
var dots = Array(75).fill(temp_map);
// dots[24]['left'] = 23;
console.log(dots[23])
dots[24].set('left', 23);
dots[23].set('right', 24)
this.setState({dots: dots});
console.log(dots)
console.log(this.state.dots)
}
In the above code I have created an array of size 75 and fill them with a map with key value pairs.
dots[24].set('left', 23);
dots[23].set('right', 24);
And I do console.log(dots) I get the following:
How does all maps in the 75 locations of the dots array get their left keys updates?
And the after I call
this.setState({dots: dots});
and then do console.log(this.state.dots) I get the following:
why does not the state gets updated. Any help is highly appreciated.