-
Notifications
You must be signed in to change notification settings - Fork 129
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
Add support for React Suspense #264
Comments
Interesting idea which I've never investigated. I'll look into what it would take to add suspense support. Thanks for bringing it up! |
I'd be happy to lend a hand! |
PRs are always welcome! |
I started doing some experiments with Suspense for data fetching but I'm not too positive that that pattern fits very well in how axios-hooks works. Aside from being still experimental, the pattern assumes that data loading begins before you even start rendering the component, and from within the component you simply get a promise that resolves or rejects in various ways, making Suspense work. This is fundamentally different from how axios-hooks currently works, as it uses a This is not to say that it's impossible to integrate it with Suspense, but early experiments don't look too promising, or in other words, I came nowhere close to making it work. |
Maybe try to get inspiration from relay or apollo-client implementation? From what I gathered from suspense docs, relay already supports it even at this work-in-progress stage, and also apollo-client (apollographql/apollo-feature-requests#162 (comment)) |
Looks like react-i18next also supports it: https://react.i18next.com/latest/using-with-hooks#using-the-usetranslation-hook |
Thanks for sharing the link. Our case here is slightly different though because translations are a perfect use case for Suspense. You load once and you're done. Here we have to handle reloading, caching, manual fetching and so on, and I think that's the part that makes the integration more complex. But I'll look into it! |
Although Suspense isn't officially ready for data fetching, some libraries already take advantage of this feature (react-hooks-fetch, built-in React.lazy...).
Why
Data loading is quite painful to handle at the time, especially when you have multiple queries.
Code handling data loading is also very repetitive.
Solution
How about adding a boolean suspend experimental option (which defaults to false) that would make useAxios throw the axios request promise to trigger the Suspense api?
The benefits of triggering Suspense are:
code becomes cleaner and simpler by allowing to write it as if everything is synchronous repetitive code to handle loading can be reduced to the usage of a component
Question is: what is the roadmap about Suspense support ? Would it be possible to have an experimental implementation in a near future? or wait for the Suspense api to be officially ready for data fetching?
Thanks
The text was updated successfully, but these errors were encountered: