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

Separate rules for 3 problems #1

Open
DanEastBentley opened this issue Nov 21, 2019 · 1 comment
Open

Separate rules for 3 problems #1

DanEastBentley opened this issue Nov 21, 2019 · 1 comment

Comments

@DanEastBentley
Copy link

Would it be possible to separate the 3 problems reported by this package into 3 separate rules so they can be disabled/enabled separately? The 3 problems are:

  • Do not pass an object into setState. Use functional setState updater instead. (tslint-react-set-state-usage)
  • Do not access 'this.props' in setState. Use arguments from callback function instead. (tslint-react-set-state-usage)
  • Do not access 'this.state' in setState. Use arguments from callback function instead. (tslint-react-set-state-usage)

Also, there is no (prevState) argument passed to the second callback parameter, so there is no way to fix the reported error about the 'this.state' usage in this snippet:
this.setState(
{ expanded: true },
() => {
if (this._menu && this.state.expanded)
this._menu.focus();
});

Thanks

@DanEastBentley
Copy link
Author

I've created a fork with a new "allow-object" option to allow objects to be passed to setState. It still reports the usage of 'this.state' and 'this.props' in setState. This is in line with the React documentation: https://reactjs.org/docs/state-and-lifecycle.html#state-updates-may-be-asynchronous.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant