react.dev icon indicating copy to clipboard operation
react.dev copied to clipboard

Recommend eslint:no-label for functional setState

Open tsiq-swyx opened this issue 7 years ago • 3 comments

this is a pretty common mistake when using the functional form of setState:

image

and we have no warning in React (yet) for this when it happens. easiest guard is having eslint:no-label tell you about it. Should we add a mention in the setState docs?

tsiq-swyx avatar Jun 26 '18 18:06 tsiq-swyx

Maybe add a note here? https://reactjs.org/docs/faq-state.html#what-is-the-difference-between-passing-an-object-or-a-function-in-setstate

alexkrolick avatar Jun 26 '18 20:06 alexkrolick

yeah. i'm also trying to add a warning in react itself: https://github.com/facebook/react/issues/13111

tsiq-swyx avatar Jun 26 '18 21:06 tsiq-swyx

On the new site I'm not sure it makes sense to recommend the lint rule, especially in 2025 where types and strict mode should catch this, but it would probably be good to have a Pitfall callout or Troubleshooting item here: https://react.dev/reference/react/useState#troubleshooting

rickhanlonii avatar May 17 '25 19:05 rickhanlonii