score:1

looks like you are unintentionally mutating the state of your component. you are not copying the object here. javascript objects are passed by reference, which means when you directly assign an object like this to another variable, they both will modify the same data.

instead of:

let copy = this.state.gameboard[currentrow].slice()

call:

let copy = object.assign({}, this.state.gameboard[currentrow]);

if it is your intention to update the state of your component you should call the.setstate({obj}).

if you have to deep clone an object, i would suggest deep copy functions from either lodash or underscore (or create your own: objects in js: deep copy).

hope this helps,

score:3

console.log is actually an async method and that is most likely why you are seeing the execution "appear" out of order. whenever you console.log an object, make sure to console.log(json.stringify(json.parse(value)));.

a better way to see execution order and its values is to add debugger statement. try adding debugger; right above step 5 and walk through the code to see what the values actually are. i would imagine the values would be as you expect them to be. if not, stepping through the process using the debugger will tell you why.


Related Query

More Query from same tag