Home  >  Article  >  Web Front-end  >  Plug-in introduction to React copy-paste function

Plug-in introduction to React copy-paste function

巴扎黑
巴扎黑Original
2017-08-23 13:58:052998browse

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: &#39;red&#39;}}>Copied.</span> : null}

    <br />

    <textarea style={{marginTop: &#39;1em&#39;}} cols="22" rows="3" />

   </p>
  );
 }
});

const appRoot = document.createElement(&#39;p&#39;);

appRoot.id = &#39;app&#39;;
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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn