Files
blitzkit/packages/website/src/hooks/useAwait.ts
T

10 lines
304 B
TypeScript
Raw Normal View History

2024-09-17 22:50:34 -05:00
import { useRef } from 'react';
2024-01-21 22:11:01 -06:00
import usePromise from 'react-promise-suspense';
/**
* A more stable alternative to `use` using `usePromise`.
*/
export function useAwait<Type>(promise: Promise<Type>) {
2024-09-17 22:50:34 -05:00
const callback = useRef(async () => await promise);
return usePromise(callback.current, []);
2024-01-21 22:11:01 -06:00
}