From 065c1633b2b83b9bdf053800cbd82c1259c1452f Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Tue, 7 Mar 2023 16:10:55 +0700 Subject: fix show page content --- src/lib/content/components/PageContent.jsx | 39 ++++++++++++++++-------------- 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'src/lib') diff --git a/src/lib/content/components/PageContent.jsx b/src/lib/content/components/PageContent.jsx index 724f99c1..60116698 100644 --- a/src/lib/content/components/PageContent.jsx +++ b/src/lib/content/components/PageContent.jsx @@ -1,26 +1,29 @@ -import { useEffect } from 'react' -import { useState } from 'react' import pageContentApi from '../api/pageContentApi' +import { useQuery } from 'react-query' +import Spinner from '@/core/components/elements/Spinner/Spinner' const PageContent = ({ path }) => { - const [content, setContent] = useState(<>) + const fetchContent = async () => await pageContentApi({ path }) + const content = useQuery(`content-${path}`, fetchContent) - useEffect(() => { - const loadContent = async () => { - const dataContent = await pageContentApi({ path }) - if (dataContent) { - setContent( -
- ) - } - } - loadContent() - }, [path]) + if (content.data) { + return ( +
+ ) + } - return content + if (content.isLoading) { + return ( +
+ +
+ ) + } + + return <> } export default PageContent -- cgit v1.2.3