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;