简体   繁体   中英

react copy to clipboard usage doesn't work

How can I copy content when it's clicked once? below is my code, but when I clicked and do ctrl + v, it's not been copied

class App extends Component {
  state = {
    value: "",
    copied: false
  };
  render() {
    return (
      <div className="App">
        <CopyToClipboard
          text={this.state.value}
          onCopy={text => this.setState({ copied: true, text })}
        >
          <span>content</span>
        </CopyToClipboard>
        {this.state.copied ? (
          <span style={{ color: "red" }}>Copied.</span>
        ) : null}
      </div>
    );
  }
}

doc: https://www.npmjs.com/package/react-copy-to-clipboard

You are not changing this.state.value in your program. Try setting it in your code with which value you are trying to copy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM