Following comes from React tutorial:
const squares = this.state.squares.slice();
squares[i] = 'X';
this.setState({squares: squares});
This code changes copied state.squares and assign it to orginal state.squares. Finally this changes original state.squares, so I think this is not different than mutable code like following:
this.state.squares[i] = 'X';
Is there some difference?
You can do this, but you should not, the reason behind is that, if you use
It will be overridden with next
So, your app will not have accurate data.
From Doc:
Check more about this in https://facebook.github.io/react/docs/react-component.html#state