I read the ReactJS documentation on setState. In particular, this line:
NEVER mutate this.state directly, since calling setState () can subsequently replace the mutation you made. Treat this.state as immutable.
But in my code, I do this:
var x = this.state.x; x.y.z.push("foo"); // z is a list this.setState({x:x});
This code is working correctly and is being updated. But according to the documentation, I break the rules. What is the problem with this approach? Are there any performance issues? Race conditions Will the Facebook development team scold me? Ideally, I would like to avoid the helpers of immutability and the rest of the craziness and make things simple.
, , this.setState, , , .
this.setState
, OOP ( , JS ...) getter setter . this.state.prop1 = "xyz";
this.state.prop1 = "xyz";
, , . . , , .
- https://facebook.imtqy.com/react/docs/component-specs.html#updating-shouldcomponentupdate
, React, React. React setState , , DOM DOM DOM DOM. , , - , , , setState. , .
setState
, , , , setState , React. , , . , , , , (.. ) setState, .
EDIT: , , , , setState, - , setState, , . setState , setState, , , , .
, shouldComponentUpdate .