TanStackT
TanStackโ€ข2y agoโ€ข
2 replies
awake-maroon

React - queryClient.getQueryData(key) - can I think about it as about useContext?

I have a situation where I fetch data in <ParentComponent /> using
useQuery
hook. I have a lot of nested children in this component and I need to display the data on the bottom of the tree and I consider following options:
- props drilling - sounds bad as usual props drilling ๐Ÿ™‚
- context - there are performance issues with the context without using useContextSelector and it's not compliant for some reason.
- queryClient.getQueryData as a mechanism to retrieve in the bottom of the tree or throw when undefined.

Considering only scenario 3:

1) Is it correct to assume data will be always defined when fetched?\
2) Does it break somehow react-query paradigms?
Was this page helpful?