restful-react icon indicating copy to clipboard operation
restful-react copied to clipboard

Suspense integration

Open elsangedy opened this issue 5 years ago • 10 comments

elsangedy avatar Oct 28 '19 20:10 elsangedy

Hey @elsangedy! Thanks for reaching out! This is a great idea! We're already working on it! Would you like to contribute?

TejasQ avatar Oct 28 '19 21:10 TejasQ

That's great @TejasQ! For sure I would like help, how can I contribute?

elsangedy avatar Oct 29 '19 17:10 elsangedy

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?

TejasQ avatar Oct 30 '19 14:10 TejasQ

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

elsangedy avatar Oct 31 '19 17:10 elsangedy

https://github.com/CharlesStover/fetch-suspense

https://github.com/zeit/swr

https://github.com/relayjs/relay-examples/pull/104/files

elsangedy avatar Oct 31 '19 17:10 elsangedy

@elsangedy how's that proposal looking? Happy to help in any way I can.

TejasQ avatar Nov 18 '19 10:11 TejasQ

@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 } })
  );

elsangedy avatar Nov 18 '19 14:11 elsangedy

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

Ugzuzg avatar Jul 25 '20 14:07 Ugzuzg

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 avatar Jan 23 '21 14:01 Alex-Ferreli

@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)

fabien0102 avatar Jan 25 '21 12:01 fabien0102