The issue involves a false positive in ESLint's react-hooks/immutability rule.
The issue reports a false positive warning from ESLint's react-hooks/immutability rule when a callback references itself internally. The fix likely requires modifying the rule's logic to handle self-references correctly. The scope is somewhat clear but requires understanding of ESLint and React hooks internals.
eslint-plugin-react-hooks version: 7.0.1
const Test: FC = () => {
const onMouseDown = useCallback(() => {
// warns here about using onMouseDown
window.removeEventListener('mousedown', onMouseDown);
}, []);
useEffect(() => {
window.addEventListener('mousedown', onMouseDown);
return () => {
window.removeEventListener('mousedown', onMouseDown);
};
}, [onMouseDown]);
return <div>Hello</div>;
};
`onMouseDown` is accessed before it is declared, which prevents the earlier access from updating when this value changes over time.
No errors
Claim this issue to let others know you're working on it. You'll earn 10 points when you complete it!