I was looking the implementation of eslint-plugin-react-hooks and it looks like useState's setState and useReducer's dispatch functions are static references which are not required to be declared in the dependency array in useEffect.
However, this rule does not seem to work properly when you write a custom rule that abstracts an internal logic. for example, I create a custom hook:
const useCustom = () => {
const [number, setNumber] = React.useState(0);
return [number, setNumber];
};
which is then used the following way:
const [number, setNumber] = useCustom();
React.useEffect(() => {
if (something) {
setNumber(1);
}
}, [something]); // useEffect has a missing dependency: 'setNumber'
Adding the dependency to the array does not seem to cause extra render cycles. However, it raises a another question: What if my hook returns a reference to an value returned from useRef() would that be safe to add it to the dependencies array?