API reference

CodeExecutor

The main rendering component.

import { CodeExecutor } from "react-exe";

<CodeExecutor
  code={code}       // string | CodeFile[]
  config={config}   // optional CodeExecutorConfig
/>

Props

PropTypeDescription
codestring | CodeFile[]Component source code, or an array of files
configCodeExecutorConfigOptional configuration object

CodeExecutorConfig

PropertyTypeDefaultDescription
sandboxbooleantrueRender inside an iframe with its own DOM and styles
enableTailwindbooleanfalseLoad Tailwind CSS for the preview
dependenciesRecord<string, any>{}Modules available to the code, keyed by import path. Keys ending in /* match any sub-path
autoResolvePackagebooleantrueLoad imports that aren't in dependencies from npm via esm.sh
onError(error: Error) => void—Called for compile, security-pattern, package-loading and render errors
securityPatternsRegExp[]see belowCode matching any pattern is held back until the user clicks "Continue Anyway"
containerClassNamestring—Class name for the preview container
containerStyleCSSProperties—Inline styles for the preview container (the sandbox defaults to minHeight: 360)
errorClassNamestring—Class name for the error panel
errorStyleCSSProperties—Inline styles for the error panel

Default securityPatterns flag document.cookie, eval(, Function(, document.write and document.location. They are heuristics, not a security boundary.

CodeFile

Used when passing multiple files via the code prop:

PropertyTypeDescription
namestringFile path, e.g. "components/Card.tsx"; .css and .json files are supported
contentstringSource for this file
isEntrybooleanMark the root component file (defaults to the first file)

Notes

  • The entry file should default-export a component. Without one, an App export or a single capitalized component export is used.
  • React is in scope inside code strings — importing it is optional.
  • Code is recompiled when its content changes; editing a string re-renders the preview.
  • Syntax errors are shown with the file name and a code frame. Runtime errors are caught by an error boundary.
Loading playground…