eslint-plugin-react-hooks version: 7.0.1
Steps To Reproduce
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>;
};
The current behavior
`onMouseDown` is accessed before it is declared, which prevents the earlier access from updating when this value changes over time.
The expected behavior
No errors