restful-react
restful-react copied to clipboard
Suspense integration
Hey @elsangedy! Thanks for reaching out! This is a great idea! We're already working on it! Would you like to contribute?
That's great @TejasQ! For sure I would like help, how can I contribute?
We've been thinking about adding support for Suspense here but have not written about it. Have you given it some thought? Do you have an idea about how you'd go about it in this project?
I already read about Suspense, and I've been seeing some examples in different libs, I'll try write a proposal to implement in restful-react
https://github.com/CharlesStover/fetch-suspense
https://github.com/zeit/swr
https://github.com/relayjs/relay-examples/pull/104/files
@elsangedy how's that proposal looking? Happy to help in any way I can.
@TejasQ what do you think about integrate with https://github.com/zeit/swr? I tried and it's worked fine. That's only a suggestion, I changed a bit the script of code generate
export type CustomersQueryParams = {keyword?: string; page?: number; itemsPerPage?: number}
export type CustomersProps = Omit<UseGetProps<CustomersList, CustomersQueryParams>, "path">;
export const customers = (props: CustomersProps) => query<CustomersList, CustomersQueryParams>(`/api/v1/customers`, props);
export const useCustomers = ({keyword, page = 1, itemsPerPage = 25}: CustomersQueryParams, options?: Omit<CustomersProps, "queryParams">) =>
useSWR<CustomersList>(
[`/api/v1/customers`, keyword, page, itemsPerPage],
() => customers({ ...options, queryParams: { keyword, page, itemsPerPage } })
);
Here's a quick and dirty attempt at using swr in useGet
, this provieds caching and suspense support:
https://github.com/Ugzuzg/restful-react/commit/f8cb6102652957b0ecc68b602a84ed0c5ad51d3d
Any news about this feature? Would be great to have support of Suspense.
This library is perfect, really easy to use and generate good code.
@Alex-Ferreli No news about this sadly, not a real need for us (yet) and not a lot of time for goodies features 😅
I never really read about all this suspense topic, but if useSWR
(https://github.com/contiamo/restful-react/issues/162#issuecomment-555047414) works well, this should not be too hard to write a little customGenerator
(https://github.com/contiamo/restful-react/blob/3d28a49e2cb0e898e030a7f2421b12b27685ff5d/examples/restful-react.config.js#L27-L42) to play with this.
(I also still want to give a try to this react-query at some point (with generator of course, I will never go back to write my types by hand ^^, but didn't really put the time on it yet)