import { SandpackPreviewRef, useSandpack, SandpackPreview, SandpackFileExplorer, Sandpack } from '@codesandbox/sandpack-react'; import { useEffect, useRef } from 'react'; import { SandpackProvider, SandpackLayout, SandpackCodeEditor } from '@codesandbox/sandpack-react'; export const App = () => { return (

Welcome to the App

This is a simple React application.

{/* */} {/* */} Hello Sandpack!; }`, './index.html': { code: `12345`, }, }} />
); }; const SandpackPreviewClient: React.FC = () => { const { sandpack } = useSandpack(); const previewRef = useRef(null); useEffect(() => { const client = previewRef.current?.getClient(); const clientId = previewRef.current?.clientId; if (client && clientId) { console.log(client); console.log(sandpack.clients[clientId]); } /** * NOTE: In order to make sure that the client will be available * use the whole `sandpack` object as a dependency. */ }, [sandpack]); return ; };