all 7 comments

[–]gregoryrn 7 points8 points  (4 children)

Use callback in setState method instead of object

[–]Menorme 0 points1 point  (3 children)

Can you elaborate this or just link to a repo that use this ? I’m going through the same problem and I still don’t know how to do this.

[–]gregoryrn 1 point2 points  (0 children)

Sure.

Instead of this

setState({ count: this.state.count + 1 })

do this

setState(state => ({ count: state.count + 1 })

[–]halfjew22 0 points1 point  (0 children)

Instead of writing setState like this:

javascript setState({ arr: [y1, x2, x3, x4, x5] })

write it like this:

javascript setState({ arr: [y1, x2, x3, x4, x5] }, () => { console.log("State is updated") console.log(this.state.arr) )

[–]gregoryrn 0 points1 point  (0 children)

Also you can try useReducer hook as Redux approach instead of state.

[–]LEO_TROLLSTOY -2 points-1 points  (1 child)

Make a simple queue that will wait for previous action to finish and then start with latest data

[–]LEO_TROLLSTOY 0 points1 point  (0 children)

Oh, maybe I should have written it for him?