Created
March 24, 2023 06:39
-
-
Save abhishekjakhar/40bb8a4795894dbed60d06d5d0ed52e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Suspense, lazy, memo, Children } from 'react'; | |
import { createFileMap } from './createFileMap'; | |
const SandpackRoot = lazy(() => import('./SandpackRoot')); | |
type PlaygroundProps = { | |
children: React.ReactNode; | |
}; | |
export default memo(function Playground(props: PlaygroundProps) { | |
const codeSnippets = Children.toArray(props.children) as React.ReactElement[]; | |
const files = createFileMap(codeSnippets); | |
return ( | |
<Suspense> | |
<SandpackRoot files={files} {...props} /> | |
</Suspense> | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment