Controlled rendering
Turn React component code strings into live browser previews inside a scoped, sandbox-friendly runtime.
A browser-based canvas for rendering React components at runtime.
bun add react-code-canvas@latest
import { ReactCanvas } from 'react-code-canvas';
const code = `
export default function Hello() {
return (
<h1 className="title">
Hello, world 👋
</h1>
);
}`;
export default function App() {
return (
<ReactCanvas
code={code}
showEditor
showPreview
persistKey="playground"
/>
);
}
Why react-code-canvas
Turn React component code strings into live browser previews inside a scoped, sandbox-friendly runtime.
Check code with analyzeReactCode() in Node — no browser, no render — and catch bad scope references before you ever save.
Let users edit rendered text in place while the original JSX is preserved and patched back automatically.
No imports in user code. You decide exactly which components, hooks, and libraries are available via scope.
Opt into localStorage with a single persistKey prop, or wire onCodeChange to your own backend.
Dual bundles with first-class TypeScript declarations, so it just works in any modern toolchain.
Install the package and render your first component in a couple of minutes.