Consider this example:
let memoizedCb = React.useCallback(
memoize((param) => () => someFunction(param)),
[]
);
where memoize
is from external library like "fast-memoize". Above code gives warning:
React Hook useCallback received a function whose dependencies are unknown. Pass an inline function instead
I found this thread which if we adapt to my use case would suggest this as solution (if I am not wrong):
const memoizedCb = React.useMemo(
() => memoize((param) => () => someFunction(param)),
[]
);
What is the warning about? why does useMemo
fix this problem?
NOTE: someFunction
is defined outside the function component so it is not needed as a dependency.