Next.js Discord

Discord Forum

Same API call in layout and page component

Unanswered
Tornjak posted this in #help-forum
Open in Discord
Avatar
TornjakOP
Hello! I was curious about something today. I'm trying to fetch things from the layout, to show data on the layout, but then I also need those data on the page itself. So I'm making a similar call in both places, and I wonder if this triggers two calls to that API.

Is that a problem you think ?

3 Replies

Avatar
Ray
you could use cache from react to dedup the request
https://react.dev/reference/react/cache#noun-labs-1201738-(2)
Avatar
TornjakOP
I'm using the T3 stack, with trpc and react query, I wonder if they are handling that automatically 🤔 thanks for your answer 🙌
Avatar
Ray
react-query should handle it if you are fetching on client side