mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-03 12:55:41 -05:00
13 lines
518 B
TypeScript
13 lines
518 B
TypeScript
import { useCallback, useState } from 'react';
|
|
|
|
/** Whether any tracked action is still running; rejections are swallowed, the panel having reported them. */
|
|
export function usePending(): [boolean, (action: Promise<unknown>) => void] {
|
|
const [count, setCount] = useState(0);
|
|
const track = useCallback((action: Promise<unknown>) => {
|
|
setCount((current) => current + 1);
|
|
void action.catch(() => {}).finally(() => setCount((current) => current - 1));
|
|
}, []);
|
|
|
|
return [count > 0, track];
|
|
}
|