Reuse fetched data
Unanswered
Japanese flying squid posted this in #help-forum
Japanese flying squidOP
Hi there, I want to know that is there a way to get the previously fetched data in another page instead of re-fetching it again like if I have a page
/user where I fetch the user data and direct the client to /user-settings where also I need the user data, so is there a way to get the data from /user route to /user-data without re-fetching it.5 Replies
Toyger
https://nextjs.org/docs/app/api-reference/functions/fetch by default fetch results are cached so you can reuse it as many times as you want, and if you want to update it later you just set revalidate to whatever fine for your case.
or you can use revalidateTag
Japanese flying squidOP
yeah i know that we can cache or revalidate but how to retrieve the cached data from another route and use it there ? that is the question
@Japanese flying squid yeah i know that we can cache or revalidate but how to retrieve the cached data from another route and use it there ? that is the question
Toyger
as I said by default data cached, so you basically run same fetch, and instead making query it will use fetched data, I am not sure how it works under the hood, is it client cache, or server cache, so theoretically request to your server still be showed in network dev tools, but it either just reuse data and fininsh request with "304 Not modified" code, or return data from cache on server.
Japanese flying squidOP
ok thanks i'll check it