Editor Mode
Live.Editor and Live.Preview share code through Live's context — edit
in the editor and the preview updates automatically. No manual wiring between
them is needed. (The preview itself isn't an editing surface — only
Live.Editor writes to the shared code.)
import { useState } from 'react';
import Live from '@jbpark/live-editor';
const SAMPLE = `
import * as ui from 'ui-kit';
const App = () => (
<div className="p-6 space-y-2">
<ui.Typography.Title level={3}>Hello from the editor</ui.Typography.Title>
<ui.Button type="primary">Edit me</ui.Button>
</div>
);
export default App;
`;
export default function EditorMode() {
const [value, setValue] = useState(SAMPLE);
return (
<Live>
<Live.Preview
showError
dynamicTailwind
frame={{ mode: 'shadow', syncStyle: true }}
/>
<Live.Editor value={value} onChange={setValue} />
</Live>
);
}
Live.Editoris a controlled CodeMirror surface — passvalue/onChange. It only pushes to the shared preview codedebouncems after you stop typing (default1000) — a full second of lag is expected, not a bug. Passdebounce={0}for immediate updates.Live.Previewcompiles the shared code and renders it;showErrorsurfaces compile/runtime errors inline.dynamicTailwindcompiles Tailwind classes from the rendered preview at runtime and injects them as a<style>tag — needed inshadowmode, which has no separate document to load a stylesheet into (see Preview Modes).
See Overview for the full prop list on both components.