The issue involves nuanced React behavior and ESLint rules.
The issue questions whether the `react-hooks/set-state-in-effect` ESLint rule is overly strict, citing common patterns that trigger warnings. It requires understanding React's effect lifecycle and potential performance impacts. The scope is somewhat clear but involves deep React knowledge.
eslint-plugin-react-hooks version: 6.1.1
eslint-plugin-react-hooks 💥Link to code example: https://codesandbox.io/p/devbox/still-resonance-lzsl44?file=%2Fapp%2FComponent.tsx%3A10%2C49&workspaceId=ws_GfAuHrswXyA1DoeSwsjjjz
$ pnpm eslint . --max-warnings 0
/project/workspace/app/Component.tsx
7:5 error Error: Calling setState synchronously within an effect can trigger cascading renders
Effects are intended to synchronize state between React and external systems such as manually updating the DOM, state management libraries, or other platform APIs. In general, the body of an effect should do one or both of the following:
* Update external systems with the latest state from React.
* Subscribe for updates from some external system, calling setState in a callback function when external state changes.
Calling setState synchronously within an effect body causes cascading renders that can hurt performance, and is not recommended. (https://react.dev/learn/you-might-not-need-an-effect).
/project/workspace/app/Component.tsx:7:5
5 |
6 | useEffect(() => {
> 7 | setDidMount(true);
| ^^^^^^^^^^^ Avoid calling setState() directly within an effect
8 | }, []);
9 |
10 | retur
Claim this issue to let others know you're working on it. You'll earn 10 points when you complete it!