so let's say I have a react dashboard application, which has several different routes. Now, one of those routes is Analytics route, and I was wondering, if is, what is the best way to fetch the data rendered in Analytics route only the first time you visit it and then pull it from somewhere.
I've been thinking about using Redux for it, but I've never used it, so I have no idea, OR if I should store it in localStorage. But that has a problem though, because on different route, I would like to fetch images the same way.
The reason I'm asking this is because I use Firebase Firestore as my DB and it could get quite costly, because I would have to do 4 read operations i.e. on the Analytics route each time it is rendered. Or, is it the normal approach?
Is it a good idea to use React Context and useContext hook in this case?
Thanks in advance.
use redux for state management, where you can store the application state and the components who need data. You can call Api in order to fetch data only first time in the root component of the app.
use react-query you can do exactly this in a much simpler way as compared to context or react-redux.
you can use a useEffect hook and do an api call each time you visit that page and you don't have to store it anywhere and it will only get you the date you need i recently made an app and this way actually helped me alot