mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 20:19:49 +02:00
feat: memo fetch
This commit is contained in:
1 parent
463371de18
commit
68d8a6925c
1 file changed
+9
-6
@@ -1,4 +1,4 @@
|
|||||||
import { use } from 'react';
|
import { use, useMemo } from 'react';
|
||||||
import { useApp } from '../stores/app';
|
import { useApp } from '../stores/app';
|
||||||
|
|
||||||
let cache: boolean | undefined = undefined;
|
let cache: boolean | undefined = undefined;
|
||||||
@@ -10,13 +10,16 @@ export function useAdExempt() {
|
|||||||
|
|
||||||
if (!patreon) return false;
|
if (!patreon) return false;
|
||||||
|
|
||||||
const json = use(
|
const promise = useMemo(
|
||||||
fetch(`/api/patreon/membership/${patreon.token}`, {
|
() =>
|
||||||
cache: 'force-cache',
|
fetch(`/api/patreon/membership/${patreon.token}`, {
|
||||||
}).then((response) => response.json()),
|
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;
|
cache = exempt;
|
||||||
|
|
||||||
return exempt;
|
return exempt;
|
||||||
|
|||||||
Reference in new issue
Block a user