A little improvement on move handling

This commit is contained in:
2026-02-07 23:11:09 +01:00
parent ddb19a4ce8
commit 1f969b8ff1
3 changed files with 25 additions and 4 deletions
+20
View File
@@ -18,6 +18,26 @@ export default function useAction<T>(
return [value, loaded, error];
}
export function useActionOnce<T>(
action: () => Promise<T>,
dependencies: any[] = [],
): [T | null, boolean, Error | null] {
const [value, setValue] = useState<T | null>(null);
const [loaded, setLoaded] = useState(false);
const [error, setError] = useState(null);
useEffect(() => {
if (loaded) return;
action()
.then(setValue)
.catch(setError)
.finally(() => setLoaded(true));
}, dependencies);
return [value, loaded, error];
}
export function useActionInterval<T>(
action: () => Promise<T>,
interval: number,