Home > Article > Web Front-end > Plug-in introduction to React copy-paste function
This article mainly introduces the sample code for copying React to the clipboard. The editor thinks it is quite good, so I will share it with you now and give it as a reference. Let’s follow the editor and take a look.
This article introduces the plug-in copy-to-clipboard that can be used to copy React to the clipboard. I would like to share it with you. The details are as follows:
Refer to the API documentation
Installation
##
npm install --save react react-copy-to-clipboard
Use
const App = React.createClass({ getInitialState() { return {value: '', copied: false}; }, onChange({target: {value}}) { this.setState({value, copied: false}); }, onCopy() { this.setState({copied: true}); }, render() { return ( <p> <h1>CopyToClipboard</h1> <input value={this.state.value} size={10} onChange={this.onChange} /> <CopyToClipboard text={this.state.value} onCopy={this.onCopy}> <span>Copy to clipboard with span</span> </CopyToClipboard> <CopyToClipboard text={this.state.value} onCopy={this.onCopy}> <button>Copy to clipboard with button</button> </CopyToClipboard> {this.state.copied ? <span style={{color: 'red'}}>Copied.</span> : null} <br /> <textarea style={{marginTop: '1em'}} cols="22" rows="3" /> </p> ); } }); const appRoot = document.createElement('p'); appRoot.id = 'app'; document.body.appendChild(appRoot); ReactDOM.render(<App />, appRoot);
The above is the detailed content of Plug-in introduction to React copy-paste function. For more information, please follow other related articles on the PHP Chinese website!