angelle-sw / use-axios-client

Make axios requests in React using hooks.
https://use-axios-client.io
MIT License
157 stars 7 forks source link

Support React Suspense #6

Open zxqx opened 5 years ago

jpangelle commented 5 years ago

Haven’t worked with suspense yet. Will have to look into it.

zxqx commented 5 years ago

I've been messing with it the last few nights - I'll throw up a PR soon with some Suspense stuff.

jpangelle commented 5 years ago

Hell ya

zxqx commented 5 years ago

So this is the API I'm toying with (and an example implementation):

const Example = () => {
  const { data, error } = useFetch('https://example.com', { suspense: true });

  if (error) {
    return <div>{error}</div>;
  }

  return <div>{data}</div>;
};

const App = () => (
  <React.Suspense fallback={'Loading...'}>
    <Example />
  </React.Suspense>
);

We could also just make separate hooks, but my thought is that it may be better to have it as an option on each hook, otherwise we'd have to make a corresponding suspense-ready hook for each regular hook (e.g. useSuspenseFetch, useSuspenseLazyFetch).

Thoughts?

cc: @bvalosek

jpangelle commented 5 years ago

Damn, that’s pretty sick. Def wanna explore that

zxqx commented 5 years ago

Will leave this issue open for now - let's use this to drop any relevant thoughts and implementation ideas as data fetching with Suspense matures.