Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule proposal: no-access-state-in-setstate #1374

Merged
merged 4 commits into from
Nov 3, 2017

Commits on Aug 9, 2017

  1. wip: Add new rule no-access-state-in-setstate

    This rule should prevent usage of this.state inside setState calls.
    Such usage of this.state might result in errors when two state calls is
    called in batch and thus referencing old state and not the current
    state. An example can be an increment function:
    
    function increment() {
      this.setState({value: this.state.value + 1});
    }
    
    If these two setState operations is grouped together in a batch it will
    look be something like the following, given that value is 1.
    
    setState({value: 1 + 1})
    setState({value: 1 + 1})
    
    This can be avoided with using callbacks which takes the previous state
    as first argument. Then react will call the argument with the correct
    and updated state, even when things happen in batches. And the example
    above will be something like.
    
    setState({value: 1 + 1})
    setState({value: 2 + 1})
    relekang authored and jaaberg committed Aug 9, 2017
    Configuration menu
    Copy the full SHA
    9bec9e9 View commit details
    Browse the repository at this point in the history

Commits on Aug 15, 2017

  1. Configuration menu
    Copy the full SHA
    2d53aa7 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    70fa3c8 View commit details
    Browse the repository at this point in the history

Commits on Aug 23, 2017

  1. Configuration menu
    Copy the full SHA
    df92a49 View commit details
    Browse the repository at this point in the history