From 1df7f2ea0e2ea0f8e01d08bd8ad38373bb3cb93e Mon Sep 17 00:00:00 2001 From: HomyeeKing Date: Fri, 15 Mar 2024 15:47:51 +0800 Subject: [PATCH] feat: use useMounted --- packages/runtime/src/dynamic.tsx | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/runtime/src/dynamic.tsx b/packages/runtime/src/dynamic.tsx index 19313e4eb7..53525d39d0 100644 --- a/packages/runtime/src/dynamic.tsx +++ b/packages/runtime/src/dynamic.tsx @@ -1,5 +1,6 @@ import type { ReactNode } from 'react'; -import React, { Suspense, lazy, useEffect, useState } from 'react'; +import React, { Suspense, lazy } from 'react'; +import useMounted from './useMounted.js'; const isServer = import.meta.renderer === 'server'; @@ -41,11 +42,7 @@ export function dynamic

(loader: Loader

, option?: DynamicOptions) { const LazyComp = lazy(() => realLoader().then(convertModule)); return (props) => { - const [hasMounted, setHasMounted] = useState(false); - - useEffect(() => { - setHasMounted(true); - }, []); + const hasMounted = useMounted(); return ssr || (!ssr && hasMounted) ? ( }>