Skip to content

False positive no-access-state-in-setstate #1604

@vhenzl

Description

@vhenzl

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 componentDidUpdate or a setState callback (setState(updater, callback)), either of which are guaranteed to fire after the update has been applied.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions