I have some custom hook.
For example
function useToggle(initialValue: boolean): [boolean, VoidFn] {
const [val, setVal] = useState<boolean>(initialValue);
const toggle = setVal(prevVal => !prevVal);
return [val, toggle];
}
It's simple and clean and works fine.
But, if I use this values in other hooks, I get some warnings, because the eslint can't understand this function is already memorized.
const [myBoolVal, toggleMyVal] = useToggle(false);
const handleClick = useCallback(() => toggleMyVal(), []); // <-- I got a warning here. My IDE talks me I have to put "toggleMyVal" into dependency array.
return <button onClick={handleClick}>{myBoolVal}</div>;
How to prevent this? Maybe there is some way to mark return value as memorized