Skip to content

False positive no-access-state-in-setstate when using this.state in a function called in the setstate callback #1931

@Aequitas737

Description

@Aequitas737

Related to #1610, which doesn't completed catch all the cases.

With version 7.10.0 when the callback calls a function which references this.state.

myFunc = () => {
   this.setState({
            ...prop,
        }, () => this.doStuff());
    }

    doStuff= () => {
        console.log(this.state.asdf);
    }

Can work around this by just passing this.state into doStuff: this.doStuff(this.state)

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