import React, { useState, Suspense } from 'react'; import { loadRemote, registerRemotes, createRemoteSSRComponent, } from '@modern-js/runtime/mf'; registerRemotes([ { name: 'dynamic_remote', entry: 'http://localhost:3053/mf-manifest.json', }, ]); const RemoteSSRComponent = createRemoteSSRComponent({ loader: () => loadRemote('dynamic_remote/Image'), loading: 'loading...', fallback: ({ error }) => { if (error instanceof Error && error.message.includes('not exist')) { return
fallback - not existed id
; } return
fallback
; }, }); const NewRemoteCom = React.lazy(() => loadRemote('dynamic_remote/Image').then((m) => { console.log('加载'); return m; }), ); const Index = (): JSX.Element => { const [showComponent, setShowComponent] = useState(false); const replaceRemote = () => { console.log('replaceRemote click'); registerRemotes( [ { name: 'dynamic_remote', entry: 'http://localhost:3056/mf-manifest.json', }, ], { force: true }, ); setShowComponent(true); }; return (

Dynamic Remote

{/* replace remote */}
Desc Host component Remote component
This component is from a dynamic remote(localhost:3053)
click button to replace new remote Loading...}> {showComponent && }
); }; export default Index;