# react-code-preview **Repository Path**: uiw/react-code-preview ## Basic Information - **Project Name**: react-code-preview - **Description**: Code edit preview for React. - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: https://uiw.gitee.io/react-code-preview - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2019-08-06 - **Last Updated**: 2022-05-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README React Code Preview --- [![Build & Deploy](https://github.com/uiwjs/react-code-preview/workflows/Build%20&%20Deploy/badge.svg)](https://github.com/uiwjs/react-code-preview/actions) [![Issues](https://img.shields.io/github/issues/uiwjs/react-code-preview.svg)](https://github.com/uiwjs/react-code-preview/issues) [![Forks](https://img.shields.io/github/forks/uiwjs/react-code-preview.svg)](https://github.com/uiwjs/react-code-preview/network) [![Stars](https://img.shields.io/github/stars/uiwjs/react-code-preview.svg)](https://github.com/uiwjs/react-code-preview/stargazers) [![Release](https://img.shields.io/github/release/uiwjs/react-code-preview)](https://github.com/uiwjs/react-code-preview/releases) [![npm version](https://img.shields.io/npm/v/@uiw/react-code-preview.svg)](https://www.npmjs.com/package/@uiw/react-code-preview) [![Gitee](https://jaywcjlove.github.io/sb/ico/gitee.svg)](https://uiw.gitee.io/react-code-preview/) Code edit preview for React. Preview Demo: https://uiwjs.github.io/react-code-preview There are often a lot of sample code in the documentation. We hope that you can run the sample code to view the rendering interface as you read the document. ## Install ```bash npm install @uiw/react-code-preview --save ``` ## Usage [![Open in CodeSandbox](https://img.shields.io/badge/Open%20in-CodeSandbox-blue?logo=codesandbox)](https://codesandbox.io/embed/polished-surf-t6ro9?fontsize=14&hidenavigation=1&theme=dark) ```jsx import Button from "@uiw/react-button"; import CodePreview from "@uiw/react-code-preview"; const code = `import Button from '@uiw/react-button'; ReactDOM.render(
, _mount_ ); `; export default function App() { return ; } ``` - `_mount_` Special strings, the compilation will be replaced. ### Props ```typescript interface CodePreviewProps extends SplitProps { prefixCls?: string; style?: React.CSSProperties; /** * To specify a CSS class, use the className attribute. */ className?: string; /** * Whether to display the border. */ bordered?: boolean; /** * `JSX` source code */ code?: string; /** * Whether to display the code interface. */ noCode?: boolean; /** * Is the background white or plaid? */ bgWhite?: boolean; /** * Only show Edit */ onlyEdit?: boolean; /** * Whether to display the preview interface. */ noPreview?: boolean; /** * Preview area does not display scroll bars */ noScroll?: boolean; /** * Modify ReactCodemirror props. */ editProps?: ReactCodeMirrorProps; /** * Dependent component */ dependencies?: Record; codePenOption?: CodepenProps & { /** * Packages that do not require comments. * @example ['uiw'] */ includeModule?: string[]; }; codeSandboxOption?: CodeSandboxProps; /** @default 'Code' */ btnText?: string; /** @default 'Hide Editor' */ btnHideText?: string; } ``` ```typescript type CodePenOption = { title?: string; html?: string; js?: string; css?: string; editors?: string; css_external?: string; js_external?: string; js_pre_processor?: string; }; type CodepenProps = CodePenOption & React.FormHTMLAttributes; ``` ```typescript type CodeSandboxProps = React.FormHTMLAttributes & { /** * Whether we should redirect to the embed instead of the editor. */ embed?: boolean; /** * The query that will be used in the redirect url. `embed` must be equal to `true`, `embed=true`. * [CodeSandbox Embed Options](https://codesandbox.io/docs/embedding#embed-options) * @example `view=preview&runonclick=1` */ query?: string; /** * Instead of redirecting we will send a JSON reponse with `{"sandbox_id": sandboxId}`. */ json?: boolean; /** * Parameters used to define how the sandbox should be created. */ files?: Record; isBinary?: boolean; }>; } ``` ## Development The components are placed in the [`src`](./src) directory. ```bash npm run watch # Listen compile .tsx files. npm run build # compile .tsx files. npm run doc ``` ### Related - [@uiw/react-markdown-preview](https://github.com/uiwjs/react-markdown-preview): React component preview markdown text in web browser. - [@uiw/react-codemirror](https://github.com/uiwjs/react-codemirror): CodeMirror component for React. @codemirror - [@uiw/react-monacoeditor](https://github.com/jaywcjlove/react-monacoeditor): Monaco Editor component for React. - [@uiw/react-markdown-editor](https://github.com/uiwjs/react-markdown-editor): A markdown editor with preview, implemented with React.js and TypeScript. - [@uiw/react-md-editor](https://github.com/uiwjs/react-md-editor): A simple markdown editor with preview, implemented with React.js and TypeScript. ### License Licensed under the MIT License.