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
I was just looking in more depth at some of the modern React API functionality, and the behavior of the newer use function in conjunction with the Suspense component has me thinking that it would be possible to eliminate the hook aspect of TanStack Query, assuming you don't need onError and onSuccess callbacks.
You could still define your QueryClient instance and store it in the QueryClientProvider, but instead of needing useContext to get the client, the use function could be used -- and even better, it can be called from anywhere within a component. Similarly, data fetches can just happen directly against API services, and as long as those fetches return a Promise, you can simply not await the promise like you normally might within queryFn, instead accessing it via use, which would be nested under a Suspense block.
This might already be possible with ensureQuery or something similar.
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
Uh oh!
There was an error while loading. Please reload this page.
-
I was just looking in more depth at some of the modern React API functionality, and the behavior of the newer
usefunction in conjunction with theSuspensecomponent has me thinking that it would be possible to eliminate the hook aspect of TanStack Query, assuming you don't needonErrorandonSuccesscallbacks.You could still define your
QueryClientinstance and store it in theQueryClientProvider, but instead of needinguseContextto get the client, theusefunction could be used -- and even better, it can be called from anywhere within a component. Similarly, data fetches can just happen directly against API services, and as long as those fetches return aPromise, you can simply notawaitthe promise like you normally might withinqueryFn, instead accessing it viause, which would be nested under aSuspenseblock.This might already be possible with
ensureQueryor something similar.Beta Was this translation helpful? Give feedback.
All reactions