TanStackT
TanStack2y ago
2 replies
verbal-lime

Best way to get data inside inner components?

Hello, thank you in advance for your time. I am really new in Tanstack query and I would appreciate your help.
I am using NextJs for a project and I have in my index this code.
const {
data: store,
isFetching,
refetch,
} = useQuery({
queryFn: () => getStore({ storeId }),
queryKey: ["store", { storeId }],
});

I want to have the data inside inner components. I want to avoid prop drilling.
Inside my child component I call the below and I have data.
const store = queryClient.getQueryData(["store", { storeId }])

The problem is that when I refresh the page store is undefined. As i read it get data from cache. Is there a better way to achieve all this?
Was this page helpful?