Rules
no-direct-set-state-in-use-layout-effect
Full Name in eslint-plugin-react-hooks-extra
Full Name in @eslint-react/eslint-plugin
Features
🔍
What it does
Disallow direct calls to the set function of useState in useLayoutEffect.
This rule only checks for direct calls to the set function of useState in useEffect. It does not check for calls to set function in callbacks, event handlers, or Promise.then functions.
Examples
The first three cases are common valid use cases because they are not called the set function directly in useLayoutEffect:
Passing
Passing
Passing
The following examples are drived from the React documentation:
Failing
Passing
Failing
Passing
Failing
Passing
Failing
Passing
Known limitations
- The
setcall touseStatein thecleanupfunction ofuseLayoutEffectwill not be checked. - The current implementation does not support determining whether a
setfunction called in anasyncfunction is actually at least oneawaitafter.
The limitation may be lifted in the future.