ReactJS, Calling setState with same parameter

The official React documentation states:

The default behavior is to re-render on every state change…

https://reactjs.org/docs/react-component.html#shouldcomponentupdate

This means that by default, render() will be executed if any of a component’s state or props values changes.

You can override this default behavior using shouldComponentUpdate(). Here’s an example that only updates if a state value changes.

shouldComponentUpdate(nextProps, nextState) {
    return this.state.someValue !== nextState.someValue;
}

Note: this example completely ignores props. So, any changes to props will not trigger render().

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)