I have to correct my previous spontaneous answer which was:
I do not agree that "it's not detrimental to include the setter in the dependencies array". Adding the setter to the dependencies array will cause the effect function to be called after every render of the component because the setter returned by the custom hook will technically always be a new function though calling it will have the same effect. So, in my opinion, the correct answer would be that you have to manually deactivate the eslint rule if and only if you are sure that it does not matter if the very first returned setter is used or one that is returned later when there is a rerender and so a re-call of the custom hook function.
If you are 100% certain that a dependency from a custom setter is not necessary, you can use eslint-disable-line.
But, it is dangerous if you really forget some other dependencies in your effect code.
For example
const [myValue, mySetter] = useMyCustomHook();
useEffect(() => {
mySetter('bla');
},
// eslint-disable-next-line
[])
Meanwhile, I have realized that in the specific case that the original setter of the state is returned in the custom hook, is really not changing because it obviously is implemented as a kind of "static callback" which does not change on re-rendering.
I would like to mention here how this can be achieved also for a custom setter function using the hook "useCallback":
export function useDoubleValue() {
const [doubleValue, setDoubleValue] = useState<number>(0);
const setSingleValue = useCallback((singleValue: number) => {
setDoubleValue(singleValue * 2);
}, [/* optional dependency from setDoubleValue - does not matter */]);
return [doubleValue, setSingleValue];
}
Now, as setSingleValue is implemented using the hook useCallback(), the function is only created once, here on mounting. So, if a page using our hook "useDoubleValue" will not re-render on every re-render ending up in a confusing render-loop. And, which is nice, we can add the dependency of the setter "setSingleValue" to the dependency list of an effect where it is called because (to avoid the warning without needing the ugly and dangerous trick with esling-disable-next-line or the like), it will not cause the effect to re-run because as a stable callback there will be no change which makes the effect to re-execute.