1.

What is the difference between this.state.name=”Thomas” and this.setState({name: “Thomas”}) ?

Answer»

FIRST of all setting the STATE directly by this.state.name=”Thomas” is not recommended in REACT.
In React we should never mutate state directly instead of using setState to CHANGE the state.

One more drawback of setting state directly is that React’s lifecycle methods — shouldComponentUpdate(), componentWillUpdate(), componentDidUpdate() and render()- depend on state transitions being CALLED with setState().



Discussion

No Comment Found