diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-11-22 08:35:21 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-11-22 08:35:21 +0700 |
| commit | 87e70c5ddc13b47ed4a9101d23174a65f52a0336 (patch) | |
| tree | 8b56787233663c96d240992593fed8d355c8b35c /src-migrate/modules/page-content | |
| parent | 00cbfa62bf4c5784b1c49c766cc2a53749a6cc43 (diff) | |
| parent | e52f0ee9516d8601ffc92df9c085c2eee763c55c (diff) | |
Merge branch 'new-release' into Feature/pengajuan-tempo
Diffstat (limited to 'src-migrate/modules/page-content')
| -rw-r--r-- | src-migrate/modules/page-content/index.tsx | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/src-migrate/modules/page-content/index.tsx b/src-migrate/modules/page-content/index.tsx index 3423ca8b..54ee0a04 100644 --- a/src-migrate/modules/page-content/index.tsx +++ b/src-migrate/modules/page-content/index.tsx @@ -10,28 +10,21 @@ type Props = { const PageContent = ({ path }: Props) => { const [localData, setData] = useState<PageContentProps>(); const [shouldFetch, setShouldFetch] = useState(false); + const [isLoading, setIsLoading] = useState(false); useEffect(() => { - const localData = localStorage.getItem(`page-content:${path}`); - if (localData) { - setData(JSON.parse(localData)); - }else{ - setShouldFetch(true); - } - },[]) - - const { data, isLoading } = useQuery<PageContentProps>( - `page-content:${path}`, - async () => await getPageContent({ path }), { - enabled: shouldFetch, - onSuccess: (data) => { - if (data) { - localStorage.setItem(`page-content:${path}`, JSON.stringify(data)); - setData(data); - } - }, - } - ); + const fetchData = async () => { + setIsLoading(true); + const res = await fetch(`/api/page-content?path=${path}`); + const { data } = await res.json(); + if (data) { + setData(data); + } + setIsLoading(false); + }; + + fetchData(); + }, []); const parsedContent = useMemo<string>(() => { if (!localData) return ''; |
