UNPKG

react-code-canvas

Version:

A browser-based canvas for rendering React components at runtime

26 lines (25 loc) 1.38 kB
import React from "react"; export interface EditReactCanvasProps { code: string; scope?: Record<string, any>; showPreview?: boolean; showEditor?: boolean; showError?: boolean; onSaveFinalCode?: (jsxCode: string) => void; onError?: (error: string) => void; /** localStorage key to persist the final saved JSX across reloads; omit to disable */ persistKey?: string; /** called whenever the final JSX changes (alongside onSaveFinalCode) */ onCodeChange?: (jsxCode: string) => void; /** full-page overlay shown until the first successful render. Defaults to * `!showEditor` -- see the same note on ReactCanvasProps.showLoader. */ showLoader?: boolean; /** replace the default spinner overlay with a custom node */ loader?: React.ReactNode; /** replaces the built-in error toast. Pass a node, or a function receiving * the error message. Requires `showError`. */ errorComponent?: React.ReactNode | ((error: string, dismiss: () => void) => React.ReactNode); /** show a dismiss button on the built-in error toast; true by default */ dismissibleError?: boolean; } export default function EditReactCanvas({ code, scope, showPreview, showEditor, showError, onSaveFinalCode, onError, persistKey, onCodeChange, showLoader, loader, errorComponent, dismissibleError, }: EditReactCanvasProps): React.JSX.Element;