The issue involves a lint rule bypass that needs to be addressed in the eslint-plugin-react-hooks.
The issue describes a scenario where `useEffectEvent` bypasses the `react-hooks/set-state-in-effect` lint rule, allowing developers to circumvent intended restrictions. The fix would likely involve updating the lint rule to account for `useEffectEvent`. The main challenge is ensuring the fix doesn't introduce new issues or false positives.
Calling setState in useEffect is marked as an error per react-hooks/set-state-in-effect lint:
const [, setState] = useState('');
useEffect(() => {
// marked as react-hooks/set-state-in-effect error
setState('test');
}, []);
However there is no lint error if the setState is wrapped in an useEffectEvent:
const onSetState = useEffectEvent(() => {
setState('test');
});
useEffect(() => {
// lint passes
onSetState();
});
This provides an easy escape hatch for developers who want to bypass the lint rule.
Every time
19.2
No compiler needed. eslint-plugin-react-hooks is 7.0.1
Claim this issue to let others know you're working on it. You'll earn 10 points when you complete it!