From 59f92072969904c9be34a373f290403738134b94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8C=E1=85=A5=E1=86=BC?= =?UTF-8?q?=E1=84=89=E1=85=A5=E1=86=A8?= Date: Mon, 30 Oct 2023 23:11:36 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20=EA=B0=9C=EB=B0=9C=EB=AA=A8=EB=93=9C?= =?UTF-8?q?=EC=9D=B8=20=EA=B2=BD=EC=9A=B0,=20msw=EB=A5=BC=20init=ED=95=9C?= =?UTF-8?q?=20=ED=9B=84=20=EB=A0=8C=EB=8D=94=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/MSWComponent/MSWComponent.tsx | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/components/MSWComponent/MSWComponent.tsx diff --git a/src/components/MSWComponent/MSWComponent.tsx b/src/components/MSWComponent/MSWComponent.tsx new file mode 100644 index 0000000..4e7314a --- /dev/null +++ b/src/components/MSWComponent/MSWComponent.tsx @@ -0,0 +1,29 @@ +import initMockAPI from '@mocks/index'; +import { useEffect, useState } from 'react'; + +interface Props { + children: React.ReactNode; +} + +const MSWComponent = ({ children }: Props) => { + const [mswStateIsReady, setMswStateIsReady] = useState(false); + + useEffect(() => { + const initMSW = async () => { + await initMockAPI(); + setMswStateIsReady(true); + }; + + if (!mswStateIsReady) { + initMSW(); + } + }, []); + + if (!mswStateIsReady) { + return <>MSW Loading....; + } + + return <>{children}; +}; + +export default MSWComponent;