Rules
no-direct-set-state-in-use-effect
Full Name in eslint-plugin-react-hooks-extra
Full Name in @eslint-react/eslint-plugin
Features
🔍
Presets
recommendedrecommended-typescriptrecommended-type-checked
What it does
Disallow direct calls to the set function of useState in useEffect.
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 useEffect:
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 ofuseEffectwill 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.