Usage with React (just an example)
See original GitHub issueDescription
First of all, thanks and congrats for clipboard.js, it is a big enhancement for every web developer.
I am using clipboard.js with React and it works. I would like to add style from material-ui.
At first I was using the data-clipboard-target attribute, then I noticed the last part of documentation that explaing how to set target dynamically.
So I solved my issue while I was opening it, just reading the docs. I just want to report my working example, to give back to the community.
Minimal example
import React from 'react'
class ResultURL extends React.Component {
  componentDidMount () {
    const {
      buttonId,
      inputId
    } = this.props
    const buttonIdSelector = `#${buttonId}`
    const Clipboard = this.props.clipboard
    this.clipboard = new Clipboard(
      buttonIdSelector, {
        target: () => document.getElementById(inputId)
      }
    )
  }
  render () {
    const {
      buttonId,
      inputId,
      value
    } = this.props
    const inputIdSelector = `#${inputId}`
    return (
      <div>
        <input
          id={inputId}
          type={'text'}
          value={value}
          readOnly
        />
        <button
          id={buttonId}
        > Copy
        </button>
      </div>
    )
  }
}
ResultURL.propTypes = {
  clipboard: React.PropTypes.func.isRequired,
  value: React.PropTypes.string,
  inputId: React.PropTypes.string.isRequired,
  buttonId: React.PropTypes.string.isRequired
}
export default ResultURL
Issue Analytics
- State:
 - Created 7 years ago
 - Reactions:7
 - Comments:12 (1 by maintainers)
 
Top Results From Across the Web
Hello World - React
It displays a heading saying “Hello, world!” on the page. Try it on CodePen. Click the link above to open an online editor....
Read more >What is React.js? (Uses, Examples, & More) - HubSpot Blog
A single-page application loads only a single HTML document on the first request. Then, it updates the specific portion, content, or body of ......
Read more >What And Why React.js - C# Corner
ReactJS is just simpler to grasp right away. The component-based approach, well-defined lifecycle, and use of just plain JavaScript make React ...
Read more >10 Famous React Apps: Examples (2022) - Brainhub
Read why these super-popular React apps use the technology: Facebook, Instagram, Netflix, Whatsapp, The New York Times, Yahoo Mail, Khan Academy, and more....
Read more >React Router DOM: How to handle routing in web apps
Only in some special cases you'll have to use <Router> directly (for example when working with Redux), so the first thing you have...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Done: https://github.com/zenorocha/clipboard.js/wiki/Guides 😉
Thanks @fibo for sharing your experience!
@Clee681 Yes it makes more sense, codepen updated, 10x