# react-copy-code

> Tool to add a copy codeblock to clipboard

Latest version **2.1.2** (published 2019-04-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-copy-code
pnpm add react-copy-code
yarn add react-copy-code
bun add react-copy-code
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.2 |
| Published | 2019-04-29 |
| First published | 2018-01-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 53.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Justin Travis Mair |
| Maintainers | jarvis1010 |
| Keywords | component, react, copy, clipboard |

## Links

- npm: https://www.npmjs.com/package/react-copy-code
- Repository: https://github.com/Jarvis1010/react-copy-code
- Homepage: https://github.com/Jarvis1010/react-copy-code#readme
- Issues: https://github.com/Jarvis1010/react-copy-code/issues
- npm.io page: https://npm.io/package/react-copy-code

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 2.1.2 (latest) — 2019-04-29
- 2.1.1 — 2019-04-23
- 2.1.0 — 2019-04-23
- 2.0.5 — 2019-03-13
- 2.0.4 — 2019-03-12
- 2.0.3 — 2019-03-12
- 2.0.2 — 2019-03-12
- 2.0.1 — 2018-12-13
- 2.0.0 — 2018-12-04
- 1.2.2 — 2018-12-03
- 1.2.1 — 2018-12-03
- 1.2.0 — 2018-06-18
- 1.1.1 — 2018-06-18
- 1.1.0 — 2018-05-21
- 1.0.6 — 2018-02-07
- … 12 more at https://npm.io/package/react-copy-code/versions

## README

# react-copy-code

react-copy-code is a component that will add a "copy to clipboard" button to 'pre code' blocks that are rendered as it's children. Children can be jsx, other components, or an html string by setting the `innerHtml` prop. If the `highlight` prop is set, it also uses [highlight.js](https://highlightjs.org/) to add the proper classes needed for highlighting code.

## Installation

`npm install react-copy-code`

## Usage

```javascript
import CodeBlock from 'react-copy-code';

const App = () => (
   <CodeBlock>
      {write the rest of your component here}
      {using as many pre code blocks you want}
   </CodeBlock>
);
```

or

```javascript
import CodeBlock from 'react-copy-code';

const App = () => (
   <CodeBlock innerHtml>
      {html string is passed in as the only child}
   </CodeBlock>
);
```

## Props

| name      |         type          | default | description                                                                                                                                                                                     |
| --------- | :-------------------: | :-----: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| element   | JSX intrinsic Element |  "div"  | Allows you to specify which element the component renders as                                                                                                                                    |
| innerHtml |         bool          |  false  | If this is set to true, it is expecting the html string to be passed as the only child. **Warning**: uses dangerouslySetInnerHTML so be sure you trust the source                               |
| highlight |         bool          |  false  | If this is set to true, It will use highlight.js to add classes that correspond to highlight.js css theme. Checkout [documentation](https://highlightjs.org/) for highlight.js for more details |
| svg       |    ReactComponent     |  null   | Allows you to pass in any SVG based React Component as the button icon                                                                                                                          |
| onCopy    |       function        |  no-op  | Allows you to pass in a function to run when the copy button is clicked                                                                                                                         |

## Contributing

In lieu of a formal styleguide, please format your code using 'prettier' prior to commit.

## Release History

- 2.1.2 Bug fix for innerHtml, update types and documentation
- 2.1.1 Bug fixes
- 2.1.0 Changed to TypeScript
- 2.0.5 Fixed issue that broke gatsby html build
- 2.0.2 - 2.0.4 Fixed Webpack bug that was bundling React with component and other bug fixes
- 2.0.1 Make safer for SSR
- 2.0.0 Update to react 16.6
- 1.2.2 Remove react and react-dom as dependancy and put it as a peer-dependancy
- 1.2.1 Remove webpack as dependancy and put it as a dev dependancy like it was always supposed to be
- 1.2.0 onCopy prop that allows you to pass a function to run when the `copy button` is clicked
- 1.1.1 Update capabilities for older browsers(PR from absoludity)
- 1.1.0 Custom SVG Icon can be passed as the button icon
- 1.0.6 Reduce Button Real estate
- 1.0.5 Icon style fits on to one line
- 1.0.4 Update to be compatable with react 15.6
- 1.0.1 - 1.0.3 Updated Documentation
- 1.0.0 Initial Stable Release

---
_Source: https://npm.io/package/react-copy-code · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
