Skip to content

Instantly share code, notes, and snippets.

@abhishekjakhar
Created March 24, 2023 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhishekjakhar/40bb8a4795894dbed60d06d5d0ed52e9 to your computer and use it in GitHub Desktop.
Save abhishekjakhar/40bb8a4795894dbed60d06d5d0ed52e9 to your computer and use it in GitHub Desktop.
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