diff --git a/sandpack-react/src/components/CodeEditor/CodeMirror.tsx b/sandpack-react/src/components/CodeEditor/CodeMirror.tsx index ce6e49698..86e8213d4 100644 --- a/sandpack-react/src/components/CodeEditor/CodeMirror.tsx +++ b/sandpack-react/src/components/CodeEditor/CodeMirror.tsx @@ -131,7 +131,10 @@ export const CodeMirror = React.forwardRef( ); const classNames = useClassNames(); - const { listen } = useSandpack(); + const { + listen, + sandpack: { autoReload }, + } = useSandpack(); const prevExtension = React.useRef([]); const prevExtensionKeymap = React.useRef([]); @@ -319,6 +322,7 @@ export const CodeMirror = React.forwardRef( themeId, sortedDecorators, readOnly, + autoReload, ]); React.useEffect( diff --git a/sandpack-react/src/presets/CustomSandpack.stories.tsx b/sandpack-react/src/presets/CustomSandpack.stories.tsx index 618c7e45a..ce8e2ea01 100644 --- a/sandpack-react/src/presets/CustomSandpack.stories.tsx +++ b/sandpack-react/src/presets/CustomSandpack.stories.tsx @@ -20,6 +20,9 @@ import { SandpackStack, UnstyledOpenInCodeSandboxButton, SandpackFileExplorer, + SandpackConsumer, + CodeEditor, + type SandpackContext, } from "../"; import { useSandpack } from "../hooks/useSandpack"; @@ -39,6 +42,69 @@ export const UsingSandpackLayout: React.FC = () => ( ); +export const UsingMultipleEditor: React.FC = (props) => { + const [isAutoReload, setAutoReload] = React.useState(true); + + return ( +
+ + + {(context: SandpackContext | null) => { + if (!context) return <>; + + const { files, updateFile, autoReload } = context; + const fileListValues = Object.values(files); + const fileListKeys = Object.keys(files); + + return ( + + + { + updateFile(fileListKeys[0], newCode, autoReload); + }} + /> + + + + { + updateFile(fileListKeys[1], newCode, autoReload); + }} + /> + + + setAutoReload((prev) => !prev)}> + Toggle autoReload to {JSON.stringify(!autoReload)} + + } + /> + + ); + }} + + +
+ ); +}; + export const UsingVisualElements: React.FC = () => (