# 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
---
[](https://github.com/uiwjs/react-code-preview/actions)
[](https://github.com/uiwjs/react-code-preview/issues)
[](https://github.com/uiwjs/react-code-preview/network)
[](https://github.com/uiwjs/react-code-preview/stargazers)
[](https://github.com/uiwjs/react-code-preview/releases)
[](https://www.npmjs.com/package/@uiw/react-code-preview)
[](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
[](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.