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 derived from the React documentation:
Failing
Passing
Failing
Passing
Failing
Passing
Failing
Passing
Known limitations
- The
set
call touseState
in thecleanup
function ofuseLayoutEffect
will not be checked. - The current implementation does not support determining whether a
set
function called in anasync
function is actually at least oneawait
after.
The limitation may be lifted in the future.
Implementation
Further Reading
See Also
no-direct-set-state-in-use-effect
Disallow direct calls to theset
function ofuseState
inuseEffect
.