feat: useAwait

This commit is contained in:
TrèsAbhi committed 2025-11-30 22:12:46 -06:00
1 parent 42cada1811
commit 4033e8618f
6 files changed
+90 -27

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
import { use } from "react";
const cache = new Map<string, Promise<unknown>>();
export function useAwait<Type>(
creator: () => Promise<Type>,
discriminator: string
) {
let promise;
if (cache.has(discriminator)) {
promise = cache.get(discriminator) as Promise<Type>;
} else {
promise = creator();
cache.set(discriminator, promise);
}
return use(promise);
}