feat: memo fetch

This commit is contained in:
TrèsAbhi committed 2024-06-16 17:09:50 -05:00
1 parent 463371de18
commit 68d8a6925c
1 file changed
+9 -6
+9 -6
View File
@@ -1,4 +1,4 @@
import { use } from 'react';
import { use, useMemo } from 'react';
import { useApp } from '../stores/app';
let cache: boolean | undefined = undefined;
@@ -10,13 +10,16 @@ export function useAdExempt() {
if (!patreon) return false;
const json = use(
fetch(`/api/patreon/membership/${patreon.token}`, {
cache: 'force-cache',
}).then((response) => response.json()),
const promise = useMemo(
() =>
fetch(`/api/patreon/membership/${patreon.token}`, {
cache: 'force-cache',
}).then((response) => response.json()),
[patreon.token],
);
const data = use(promise);
const exempt = typeof json === 'boolean' && json;
const exempt = typeof data === 'boolean' && data;
cache = exempt;
return exempt;