Browse Source

[Beta] Use React versions from package.json (#5100)

main
dan 2 years ago
committed by GitHub
parent
commit
bd0f7c02f0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      beta/src/components/MDX/Sandpack/SandpackRoot.tsx

10
beta/src/components/MDX/Sandpack/SandpackRoot.tsx

@ -13,7 +13,6 @@ import type {SandpackSetup} from '@codesandbox/sandpack-react';
type SandpackProps = {
children: React.ReactNode;
autorun?: boolean;
setup?: SandpackSetup;
showDevTools?: boolean;
};
@ -68,7 +67,7 @@ ul {
`.trim();
function SandpackRoot(props: SandpackProps) {
let {children, setup, autorun = true, showDevTools = false} = props;
let {children, autorun = true, showDevTools = false} = props;
const [devToolsLoaded, setDevToolsLoaded] = React.useState(false);
const codeSnippets = React.Children.toArray(children) as React.ReactElement[];
const files = createFileMap(codeSnippets);
@ -78,6 +77,13 @@ function SandpackRoot(props: SandpackProps) {
hidden: true,
};
let setup;
if (files['/package.json']) {
setup = {
dependencies: JSON.parse(files['/package.json'].code).dependencies,
};
}
return (
<div className="sandpack sandpack--playground sandbox my-8">
<SandpackProvider

Loading…
Cancel
Save