One should never update the state directly because of the following reasons:

  • If you update it directly, calling the setState() afterward may just replace the update you made.
  • When you directly update the state, it does not change this.state immediately. Instead, it creates a pending state transition, and accessing it after calling this method will only return the present value.
  • You will lose control of the state across all components.

Note: Out of all the react questions, this is one that actually helps the interviewer to judge your level of understanding in this subject. Read the answer carefully to understand it properly.

BY Best Interview Question ON 19 Jul 2020