bigbuffet-rw/app/soapbox/hooks/useLoading.ts

19 lines
381 B
TypeScript
Raw Normal View History

2023-03-23 16:42:34 -07:00
import { useState } from 'react';
function useLoading() {
const [isLoading, setIsLoading] = useState<boolean>(false);
function setPromise<T>(promise: Promise<T>) {
setIsLoading(true);
promise
.then(() => setIsLoading(false))
.catch(() => setIsLoading(false));
return promise;
}
return [isLoading, setPromise] as const;
}
export { useLoading };