andreiduca / use-async-resource

A custom React hook for simple data fetching with React Suspense
https://dev.to/andreiduca/practical-implementation-of-data-fetching-with-react-suspense-that-you-can-use-today-273m
ISC License
94 stars 9 forks source link

Get a `loading` property? #118

Closed FezVrasta closed 1 year ago

FezVrasta commented 1 year ago

Hi, first of all thanks for this library, it's great.

I'm working with React Native and I would need a loading boolean to make ScrollView RefreshControl work.

I tried the useTransition hook but it doesn't seem to do what I need.

const [refreshing, startTransition] = useTransition();
const refresh = useCallback(() => {
  resourceCache(stuffLoader).clear();
  startTransition(() => {
    getStuff();
  });
}, []);

I don't think I can get away with suspense in this case, is there any escape hatch to get a simple boolean?

FezVrasta commented 1 year ago

nm! it actually works, but I was passing the wrong argument to resourceCache, that should be the async function itself, the one passed to useAsyncResource.