-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed
Labels
Description
Rule no-access-state-in-setstate is false positive if this.state is used in callback (setState's second argument).
Example:
handleChange = (value) => {
this.setState(prevState => someLogicToMutateState(prevState, value), () => {
this.props.onChange(this.state); // accessing this.state here is save but it's reported
});
};React documentation says:
…use
componentDidUpdateor asetStatecallback (setState(updater, callback)), either of which are guaranteed to fire after the update has been applied.