You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** * a custom hook that makes it easier to manage * a loading state with multiple consumers that can * declare they are loading, such as a component waiting * on two separate network requests. Returns whether isLoading, * and a `startLoading` and `finishLoading` function to wrap around critical sections like so: * @example * useEffect(() => { * startLoading(); * await networkFetch(); * finishLoading(); * }, []); */exportfunctionuseLoadingSemaphore(){const[loadingSemaphore,setLoadingSemaphore]=React.useState(0);// use useRef to stabilize the references (ok since setLoadingSemaphore is guaranteed stable)conststartLoading=React.useRef(()=>setLoadingSemaphore((p)=>p+1)).current;constfinishLoading=React.useRef(()=>setLoadingSemaphore((p)=>p-1)).current;constisLoading=loadingSemaphore>0;return{
isLoading,
startLoading,
finishLoading,};}
this hook is generic and useful, should consider it for adding
The text was updated successfully, but these errors were encountered:
this hook is generic and useful, should consider it for adding
The text was updated successfully, but these errors were encountered: