This package helps you integrate WebContainers into your React application.
pnpm add react-webcontainersWebContainers requireSharedArrayBuffer, which, in turn, requires the website where they are running to be cross-origin isolated. Because of that, you'll need to set COOP/COEP headers:
Cross-Origin-Embedder-Policy: require-corpCross-Origin-Opener-Policy: same-originTo learn more about this topic and see how to do it, check Configuring Headers.
importWebContainerProviderfrom"react-webcontainers";exportdefaultfunctionProviders({ children }: {children: React.ReactNode}){return<WebContainerProvider>{children}</WebContainerProvider>;}import{useWebContainer}from"react-webcontainers";exportdefaultfunctionPage(){constwebContainer=useWebContainer();return(<h1>{webContainer
? `WebContainer instance instantiated at ${webContainer.workdir}.`
: "WebContainer instance still booting."}</h1>);}