mirror of
https://github.com/Nezumi-2711/next-gdrive-index.git
synced 2026-09-22 20:01:36 +00:00
24 lines
537 B
TypeScript
24 lines
537 B
TypeScript
"use client";
|
|
|
|
import { DependencyList, useEffect, useState } from "react";
|
|
|
|
type Props = {
|
|
awaitFor?: () => Promise<void>;
|
|
deps?: DependencyList;
|
|
};
|
|
export default function useLoading(awaitFor?: () => Promise<void>, deps: DependencyList = []) {
|
|
const [loading, setLoading] = useState<boolean>(true);
|
|
|
|
useEffect(() => {
|
|
if (awaitFor) {
|
|
awaitFor().finally(() => setLoading(false));
|
|
} else {
|
|
setLoading(false);
|
|
}
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, deps);
|
|
|
|
return loading;
|
|
}
|