-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
no-did-mount-set-state
is triggered by setState
in ES6 arrow functions
#56
Comments
I'm afraid we cannot detect that the callback is not immediately invoked during In this case I suggest you to rewrite your code not to have setState in /*eslint-disable react/no-did-mount-set-state */
someClass.onSomeEvent((data) => this.setState({data: data}));
/*eslint-enable react/no-did-mount-set-state */ or someClass.onSomeEvent((data) => this.setState({data: data})); // eslint-disable-line react/no-did-mount-set-state Sorry for not having a better solution there :| |
Would it be possible to make this option configurable ex: strict (false positives) and loose mode (false negatives)? componentDidMount is a common place to set up event handlers so some kind of lenient loose mode could be helpful. |
Do you have an idea of the logic followed by the rule in strict and loose modes ? Currently the rule is very simple: if it find a |
My thinking is that strict mode would use the current behavior, and loose mode would suppress the warning if |
Good idea, it should do the trick. I will work on this. |
@yannickcr Thanks =) |
Awesome, thanks so much for this! |
This code triggers the
no-did-mount-set-state
rule:The error is triggered both when I use an expression and a statement body after the arrow (i.e. with curly braces).
This shouldn't trigger the rule, since the callbacks are obviously not invoked during
componentDidMount
but only at a later time.The text was updated successfully, but these errors were encountered: