Next.js Discord

Discord Forum

is there such thing such as useRouteData

Answered
Gharial posted this in #help-forum
Open in Discord
GharialOP
im exploring the new app dir and wondering if theres such a thing, similar to remix, does it exist? for example I fetch my user data on root server route would I be able to use the data on every page? thanks!

5 Replies

@Gharial im exploring the new app dir and wondering if theres such a thing, similar to remix, does it exist? for example I fetch my user data on root server route would I be able to use the data on every page? thanks!
European sprat
You can just make the same fetch call in server components and next automatically dedupes. If you have children client components you can fetch in the server component and pass the data as props.
GharialOP
thats great but I think having something like useRouteLoaderData(like remix does) ensures I dont call the same thing and do nothing
European sprat
i'm not sure how remix works but i'm just letting you know how it does work with nextjs. i'd suggest reading through this part of the docs:

https://nextjs.org/docs/getting-started/react-essentials

and also the docs on data fetching:

https://nextjs.org/docs/getting-started/react-essentials#data-fetching
Answer