React docs example shows only [a, b] as dependencies. Function doSomething is not passed.
const memoizedCallback = useCallback(
() => {
doSomething(a, b);
},
[a, b],
);
But later docs reads:
every value referenced inside the callback should also appear in the dependencies array.
My question: do I need to pass doSomething as well?
const memoizedCallback = useCallback(
() => {
doSomething(a, b);
},
[a, b, doSomething],
);
doSomethingdefined? Can it ever change?doSomethingis defined within the component or custom hook, or is passed as a parameter, then yes. If it's defined outside the function scope, then no.