https://nkbt.github.io/react-copy-to-clipboard/

    1. npm install react-copy-to-clipboard
    1. const initState = {value: '', copied: false}
    2. function App() {
    3. const [state, setState] = useState(initState);
    4. cosnt onCopy = () => {
    5. setState({copied: true});
    6. };
    7. const onClick = ({target: {innerHTML}}) => {
    8. console.log(`Clicked on "${innerHTML}"!`);
    9. };
    10. return (
    11. <CopyToClipboard
    12. onCopy={onCopy}
    13. options={{message: 'Whoa!'}}
    14. text={state.value}
    15. >
    16. <button onClick={onClick}>Copy to clipboard with onClick prop</button>
    17. </CopyToClipboard>
    18. )
    19. }