How do you persist data from a fetch and only fetch again if the data changed?
Answered
Transvaal lion posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Transvaal lionOP
I'm not super sure what would be the best approach for this.
I have a
I would like to fetch it one time and check if there's any sort of data already in the client, then there's no need to fetch again. How would I approach this problem?
I have a
NextAuth
application that fetches an access token and I then use the access token to access data from an API. What would be the more ideal way to persist data
from the API, so I don't need to do unnecessary fetches and store it locally on the user's client? Do I store it on next-auth
? Do I store it on localStorage
? I would like to fetch it one time and check if there's any sort of data already in the client, then there's no need to fetch again. How would I approach this problem?
13 Replies
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Cape horse mackerel
Install
@tanstack/react-query
and hit itAnswer
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Transvaal lionOP
Is this the conventional way to approach this? How did people cache the data before this package?
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
most people store the cache in redux state before react-query exists
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Transvaal lionOP
Ah, I see! What about
localStorage
? Is this used for something else? I'm trying to see what was the approach used with just HTML, CSS and JavaScript and I'll be done with this thread.![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
if you store in localstorage, how do you know if the data has changed?
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Transvaal lionOP
Makes sense. What was used pre-React, just HTML, CSS and JavaScrit?
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
for what? for building a website?
what are you trying to build? why would you want to use old tools lol
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Transvaal lionOP
Yes! For building a web application.
I need to understand it. Point me in the right direction and I'll read on it.
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
jquery was very popular
php + jquery
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Transvaal lionOP
Perfect! Thank you!