Same API call in layout and page component
Unanswered
Tornjak posted this in #help-forum
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 ?
Is that a problem you think ?
3 Replies
@Tornjak 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 ?
you could use
https://react.dev/reference/react/cache#noun-labs-1201738-(2)
cache
from react to dedup the requesthttps://react.dev/reference/react/cache#noun-labs-1201738-(2)
TornjakOP
I'm using the T3 stack, with trpc and react query, I wonder if they are handling that automatically 🤔 thanks for your answer 🙌
@Tornjak I'm using the T3 stack, with trpc and react query, I wonder if they are handling that automatically 🤔 thanks for your answer 🙌
react-query should handle it if you are fetching on client side