Open zxqx opened 5 years ago
I've been messing with it the last few nights - I'll throw up a PR soon with some Suspense stuff.
Hell ya
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
Damn, that’s pretty sick. Def wanna explore that
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.
Haven’t worked with
suspense
yet. Will have to look into it.