T
TanStack12mo ago
rival-black

Pattern for data fetching

Which pattern is better in the following case (react query plus next js) A page where multiple child and grand child are dependent on some data from an api let's say user info api Let say some component uses name, someuses contact and some use other things Soo 1. I make the request at the top of the page Store data in zustand (any state management library) and my components just use that or I pass down data, but here I make my page 'use client' 2. Each component makes same request with same key ('user-data')
6 Replies
harsh-harlequin
harsh-harlequin12mo ago
do you want to use nextjs with start?
rival-black
rival-blackOP12mo ago
Yes I'm using the server pages aka react server component Soo I'm curious which is better
harsh-harlequin
harsh-harlequin12mo ago
how does that mix with start? I have no next experience so I need some more context
rival-black
rival-blackOP12mo ago
Basically in first you lose server components thing but make request once.
harsh-harlequin
harsh-harlequin12mo ago
what you describe can be solved using TanStack Router context quite easily. in one parent route's beforeLoad you perform that API call and return the value.. then the value is available to child routes via router context
rival-black
rival-blackOP12mo ago
I don't think we can use that I Next, I need to dig in

Did you find this page helpful?