use-axios-client icon indicating copy to clipboard operation
use-axios-client copied to clipboard

Support React Suspense

Open zxqx opened this issue 5 years ago • 6 comments

zxqx avatar Aug 12 '19 21:08 zxqx

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

jpangelle avatar Aug 14 '19 04:08 jpangelle

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

zxqx avatar Aug 14 '19 04:08 zxqx

Hell ya

jpangelle avatar Aug 14 '19 04:08 jpangelle

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

zxqx avatar Aug 14 '19 14:08 zxqx

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

jpangelle avatar Aug 14 '19 14:08 jpangelle

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.

zxqx avatar Aug 19 '19 15:08 zxqx