Suppose I am using useEffect to prefetch data on initial rendering:
function myComponent(props) {
const { fetchSomething } = props;
...
...
useEffect(() => {
fetchSomething();
}, []);
...
...
}
My linter warn me for "React Hook useCallback has missing dependencies". It wants me to put fetchSomething inside the dependencies array.
The issue is that even it fetchSomething is going to be changed, I don't want the component to refetch the data. And as I see it, most of the situations where useEffect uses a function, it doesn't really care whether the function is changed.
I don't want to turn off that warning and doesn't like to spread // eslint-disable-next-line react-hooks/exhaustive-deps all over my code.
What is the rational behind such behavior?
It makes me feel insecure while using hooks, as if I am doing something incorrect.