When I go to /books, it fetches data from the database and seems empty when the page first load.
I see many websites, it only takes sometimes when I visit a certain route first time after that it don’t take any time to show data.
How I achieve this type of functionality.
Thanks
This is my useFirestore file.
I want when component first renders then only it takes time to load and when I visit that route the second time, it doesn’t take any time.
Well, that sounds like caching. You can implement your own hook, or use a premade hook like SWR. Just searching for fetch hook will give you a bunch of results. Although if you want it to use Redux or persist using local storage or whatnot you may have to look for more specific implementation examples.
No, it does basically the same thing you’ve written there but for any HTTP request + some extra functionality for caching. I would advise reading the SWR code and understanding it – it’s a tiny little library