educative.io

Memoized function with React’s `useCallback` Hook: Are we storing anything in memory?

I am under the impression that memoization is a caching technique, and I assumed that useCallback Hook was caching our fetched data in the computer’s memory and somehow retrieving the data from it if the term had been fetched before. And that the fetch function would only be triggered if the search term changed.

However, I am confused as to whether useCallback is storing anything in memory or if we are re-fetching data every time the search term changes.

example:
searchTerm: example1 -----> trigger a fetch of the data
searchTerm: example2 -----> trigger a re-fetch of the data
searchTerm: example2 -----> does NOT trigger a re-fetch of the data (makes sense)
searchTerm: example1 -----> trigger a re-fetch of the data …. so are we re-fetching the same data?
Is this what is happening?
or
fetch searchTerm: example1 -----> check if we have fetched this data before, if not trigger a fetch of the data & store it in memory
fetch searchTerm: example2 -----> check if we have fetched this data before, if not trigger a fetch of the data & store it in memory
fetch searchTerm: example1 -----> check if we have fetched this data before. Yes, we have seen this term before, therefore, return data from caching implementation.

Any guidance will be greatly appreciated.
Thank you all for your support in my learning journey.


Course: https://www.educative.io/courses/react-fundamentals
Lesson: Educative: Interactive Courses for Software Developers