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?
2 Replies
quickest-silver•2y ago
please read: https://tkdodo.eu/blog/react-query-as-a-state-manager
and: https://tkdodo.eu/blog/thinking-in-react-query
React Query as a State Manager
Everything you need to know to make React Query your single source of truth state manager for your async state
Thinking in React Query
In this talk, we will learn how a different mindset can help us understand React Query and work with it efficiently.
optimistic-goldOP•2y ago
@TkDodo 🔮 thank you I will read those articles