mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 02:37:05 +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';
|
||||
|
||||
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;
|
||||
|
||||
Reference in new issue
Block a user