Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react copy to clipboard

onClick={() => {navigator.clipboard.writeText(this.state.textToCopy)}}
Comment

how to copy to clipboard in react js

<button 
  onClick={() =>  navigator.clipboard.writeText('Copy this text to clipboard')}
>
  Copy
</button>
Comment

react copy to clipboard

<button 
  onClick={() =>  navigator.clipboard.writeText('Copy this text to clipboard')}
>
  Copy
</button>
Comment

react copy to clipboard button

 <buttononClick={() => navigator.clipboard.writeText("Copy this text to clipboard")}>
  Copy
</button>
Comment

copy to clipboard reatjs

import React, { useRef, useState } from 'react';

export default function CopyExample() {

  const [copySuccess, setCopySuccess] = useState('');
  const textAreaRef = useRef(null);

  function copyToClipboard(e) {
    textAreaRef.current.select();
    document.execCommand('copy');
    // This is just personal preference.
    // I prefer to not show the the whole text area selected.
    e.target.focus();
    setCopySuccess('Copied!');
  };

  return (
    <div>
      {
       /* Logical shortcut for only displaying the 
          button if the copy command exists */
       document.queryCommandSupported('copy') &&
        <div>
          <button onClick={copyToClipboard}>Copy</button> 
          {copySuccess}
        </div>
      }
      <form>
        <textarea
          ref={textAreaRef}
          value='Some text to copy'
        />
      </form>
    </div>
  );
}
Comment

react copy to clipboard

import {CopyField} from '@eisberg-labs/mui-copy-field';

<CopyField
  label="Click on copy Button"
  value={"Enter text"}
  onCopySuccess={console.log}
  onCopyError={console.log}
  copyTooltip={"Some copy tooltip. Default is Copy"}
/>
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript download json 
Javascript :: firebase auth sign out javascript 
Javascript :: get link js 
Javascript :: regex find img tag 
Javascript :: find password input jquery 
Javascript :: blob to file javascript 
Javascript :: remove last two elements array javascript 
Javascript :: Playing sound in Vue.js 
Javascript :: username regex 
Javascript :: javascript numero al cuadrado 
Javascript :: useRoutes exact path match in react 
Javascript :: run javascript from uri 
Javascript :: express body-parser deprecated 
Javascript :: jquery class list 
Javascript :: how to open html file with javascript 
Javascript :: return early pattern for functions javascript 
Javascript :: js round to nearest thousand 
Javascript :: javascript full screen 
Javascript :: allow only letters javascript 
Javascript :: divide intagers javascript 
Javascript :: add set time out in jquery 
Javascript :: find the words separated by whitespace in a string javascript 
Javascript :: adonis order by relation 
Javascript :: console regex 
Javascript :: js get current date 
Javascript :: jquery datatable get data array 
Javascript :: monitor changes made to object 
Javascript :: detect mi browser 
Javascript :: jsx emmet vscode 
Javascript :: javascript trigger click on element 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =