An open API service indexing awesome lists of open source software.

https://github.com/kunyan/react-code-container


https://github.com/kunyan/react-code-container

react

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

        

# react-code-container

[![NPM](https://img.shields.io/npm/v/react-code-container.svg)](https://www.npmjs.com/package/react-code-container) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

![image](.github/screenshot.png)

## Install

```bash
npm install --save react-code-container
```

## Usage

```tsx
import React, { useState } from 'react';
import 'react-code-container/dist/styles/base.css';
import 'highlight.js/styles/atom-one-dark.css'; // Find any highlight style you need
import ReactCodeContainer from 'react-code-container';

export default () => {
const [language, setLanguage] = useState('jsx');
const [showLineNumber, setShowLineNumber] = useState(true);

const code = `export function hello() => {
console.log("Hello world")
}`;
return (

);
};
```

## Configuration

| Option | Required | Default | Description |
| ------------------- | -------- | ------- | ----------------------------------------------- |
| `code` | required | | Your code which want to display |
| `showLineNumber` | optional | `true` | You can turn on / off line number |
| `language` | optional | | Leave empty will use auto detect |
| `onLineNumberClick` | optional | | The callback function if you clicked lineNumber |

## License

MIT © [Kun Yan](https://github.com/kunyan)