If the call to this.setState makes no changes to state, does it still call render?

Question

In the context of this exercise, if the call to this.setState makes no changes to state, does it still call render?

Answer

Yes, this.setState will always lead to calling render, unless shouldComponentUpdate returns false. By default, shouldComponentUpdate always returns true.

To prevent this, you can override the implementation of shouldComponentUpdate to return false if there was no change in state, and true only if there was a change in state. If it returns false, then render will not be called.

1 Like