Skip to content

Commit

Permalink
feat: use useMounted
Browse files Browse the repository at this point in the history
  • Loading branch information
HomyeeKing committed Mar 15, 2024
1 parent 7dc77fd commit 1df7f2e
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions packages/runtime/src/dynamic.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -41,11 +42,7 @@ export function dynamic<P = {}>(loader: Loader<P>, 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) ? (
<Suspense fallback={<Fallback />}>
Expand Down

0 comments on commit 1df7f2e

Please sign in to comment.