-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Support for Suspense in RTK Query #1574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
RTK 1.7 will have the necessary internal changes for that. (see #1277) After that we'll probably release an external package marked as "unstable" with a module for suspense hooks. |
Awesome :) Is there anything that documents upcoming changes? I did a search for "Suspense" in the issues but nothing that looked relevant came up. |
Not really, but you will need the new |
Looks like 1.7 released last month, and the suspense is killing me ;) |
All the building blocks for it are there now, so you could build your own hooks or RTK Query plugin for it at this time. But I don't have the capacity to build anything at the moment. If you want this functionality in the near future, it probably has to come from the community. |
Moving loading states out of components into Suspense looks like the way forward and there seems to be a lot of work going in other frameworks to accomodate. Will there be any first-class Suspense support in RTK Query in the future? |
@laurencefass yes, for example in the PR #2245 directly above your answer. The point is though, that Suspense has not officially been declared as "ready for use with client-side libraries" by the React team yet, but only as "ready for use if you use an opinionated framework like next if that supports it". |
I ended up writing my own quick-and-dirty hook using
|
For the record, I just built a proof of concept "Suspense Cache" using RTK Query. Not final yet, but you can see the PR here: This lets you do: function MyComponent() {
const data = getDataFromSuspenseCache()
// render here
} while encapsulating the whole "throw a promise or return the data" thing. (fixed the wrong PR link) |
Relevant thoughts over in the React Query repo: Also probably outdated discussion on Twitter: |
Dropping this in here for future reference: |
Redux Toolkit and RTK Query are awesome, and have really made it easier to get things working quickly and well.
What would be really good though is to have support for the React Suspense API, so that we can render a fallback component whilst data is loading without needing to handle it in-component with the
isLoading
flag.It's not a huge deal, but it just makes things that little bit neater to have a wrapper around the component that handles this instead.
Cheers
The text was updated successfully, but these errors were encountered: