During the job interview, I was asked how to optimize a component in React.
So I answered with an example of using useCallback and useMemo hooks.
Because whenever a components re-renders, functions and variables declared inside of the component are newly created which results in those newly created values occupying memory space.
However, with a help of those two hooks, it is possible to save memory because using useCallback and useMemo prevents creating the function and variable again and again by saving and reusing the previous result, as long as a state inside the dependency array is not changed during the component re-rendering.
So far, this was my answer. But the interviewer said useCallback does not prevent creating a function. Even if useCallback is used, a function is still created.
I do not get this part. How is the function created again inside the useCallback hook?
Is there something I'm missing about useCallback and useMemo?