You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi ✋,
I have this example (Tanstack query V5.36.0), where I try to understand why <Suspense> fallback are not rendered when I call refetch() :
import{QueryClient,QueryClientProvider,queryOptions,useSuspenseQuery,}from'@tanstack/react-query';importReact,{Suspense}from'react';constfetchDataQuery=()=>queryOptions({queryKey: ['data'],queryFn: async()=>{returnnewPromise((resolve)=>{setTimeout(()=>resolve([{lines: [{name: 'test 1',description: 'test 1 description',},{name: 'test 2',description: 'test 2 description',},],description: '',label: 'Shop 1',uuid: 'd23ac002-5444-4bf4-8f5b-0dbff30f73f9',},{lines: [{name: 'shop name 2',description: 'shop name 2 description',},],description: '',label: 'Shop 2',uuid: '443ac002-5444-4bf4-8f5b-0dbff30f73f9',},]),3000);});},});constTableComponent=({ index }: {index: number})=>{const{ data, refetch }=useSuspenseQuery(fetchDataQuery());constonClick=()=>{console.log('onClick TableComponent index = ',index);returnrefetch();};return(<><table><thead><th>Name</th><th>Description</th></thead><tbody>{data[index]?.lines.map((field: any)=>{return(<trkey={field.name}><td>{field.name}</td><td>{field.description}</td></tr>);})}</tbody></table><buttononClick={onClick}>Refetchtable</button><hr/></>);};constPanelComponent=({ index }: any)=>{const{ data, refetch }=useSuspenseQuery(fetchDataQuery());constonClick=()=>{console.log('onClick PanelComponent index = ',index);refetch();};return(<section><header>{data[index]?.label}</header><buttononClick={onClick}>Refetchpanel</button><TableComponentindex={index}/></section>);};constPanelSuspenseComponent=({ index }: {index: number})=>{return(<Suspensefallback={<div>LoadingPanel(index={index})...</div>}><PanelComponentindex={index}/></Suspense>);};constPanelsComponent=()=>{const{ data }=useSuspenseQuery(fetchDataQuery());returndata.map((group: any,index: number)=>{return<PanelSuspenseComponentindex={index}key={group.uuid}/>;
});};constPageTitleComponent=()=>{const{ data, refetch }=useSuspenseQuery(fetchDataQuery());constonClick=()=>{console.log('onClick PageTitleComponent');returnrefetch();};return(<><header><buttononClick={onClick}>Refetch{data.length}panels</button></header><hr/></>);};constqueryClient=newQueryClient();constPage=()=>{return(<QueryClientProviderclient={queryClient}><Suspensefallback={<div>LoadingPagetitle...</div>}><PageTitleComponent/></Suspense><Suspensefallback={<div>LoadingbydefaultPanels...</div>}><PanelsComponent/></Suspense></QueryClientProvider>);};exportdefaultPage;
It's a simple page, that fetch data from a single query and display it on a panel that contains table.
The main objective is to test if I can have 3 different loadings when I call refetch() on :
TableComponent -> reload only the concerned table
PanelComponent -> reload only the concerned panel
PageTitleComponent -> reload the full page (2 Suspense of the Page component)
<Suspense> fallback components are rendered on the initial loading but never following a call to refetch(). I certainly misusing this feature, but I don't see my error(s) 😓
I haven't found a way to debug the problem, by catch/observe Promise called by <Suspense /> children components 😢 .
Can you help me to understand this issue ?
Thanks in advance 🙏
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi ✋,
I have this example (Tanstack query V5.36.0), where I try to understand why
<Suspense>
fallback are not rendered when I call refetch() :It's a simple page, that fetch data from a single query and display it on a panel that contains table.
The main objective is to test if I can have 3 different loadings when I call refetch() on :
<Suspense>
fallback components are rendered on the initial loading but never following a call to refetch(). I certainly misusing this feature, but I don't see my error(s) 😓I haven't found a way to debug the problem, by catch/observe Promise called by
<Suspense />
children components 😢 .Can you help me to understand this issue ?
Thanks in advance 🙏
Beta Was this translation helpful? Give feedback.
All reactions