Copy to clipboard React component
Based on copy-to-clipboard
Would try to use execCommand with fallback to IE specific clipboardData interface and finally, fallback to simple prompt with proper text content & 'Copy to clipboard: Ctrl+C, Enter'
npm install --save react react-copy-to-clipboard
Don't forget to manually install peer dependencies (
react) if you use npm@3.
bower install --save https://unpkg.com/react-copy-to-clipboard/bower.zip
then include as
(Module exposed as `CopyToClipboard`)
;;;;const App =;const appRoot = document;documentbody;ReactDOM;
Text to be copied to clipboard
Optional callback, will be called when text is copied
result (bool): Returns
true if copied successfully, else
Optional copy-to-clipboard options.
See API docs for details
CopyToClipboard is a simple wrapping component, it does not render any tags, so it requires the only child element to be present, which will be used to capture clicks.
<CopyToClipboard text="Hello!"><button>Copy to clipboard</button></CopyToClipboard>
Currently is being developed and tested with the latest stable
Node 7 on
To run example covering all
CopyToClipboard features, use
npm start dev, which will compile
git clone email@example.com:nkbt/react-copy-to-clipboard.gitcd react-copy-to-clipboardnpm installnpm start dev# thenopen
# to run testsnpm start test# to generate test coverage (./reports/coverage)npm start test.cov# to run end-to-end testsnpm start test.e2e