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 :: website design html css javascript 
Javascript :: file upload javascript 
Javascript :: javascript two decimal places after division 
Javascript :: remove an element from array 
Javascript :: preg_match javascript 
Javascript :: jquery select first matching element 
Javascript :: hover material ui styles 
Javascript :: post method 
Javascript :: sequelize change column 
Javascript :: change the border of an image js 
Javascript :: vscode rest api extention POST method 
Javascript :: npm run js file from command line 
Javascript :: angular capitalize first letter 
Javascript :: normalize javascript 
Javascript :: String.toLower() js 
Javascript :: node sass version react 
Javascript :: how to filter json array in javascript 
Javascript :: js loader 
Javascript :: sorting in javascript 
Javascript :: how to get a user input in js 
Javascript :: js create element 
Javascript :: javascript convert to array 
Javascript :: puppeteer headless 
Javascript :: hexstring to rgb array js 
Javascript :: modulo operator in javascript 
Javascript :: winston logger creating particular log file for each level 
Javascript :: get only numbers from string 
Javascript :: xmlhttprequest js 
Javascript :: js loop through object keys 
Javascript :: redux dispatch no connect 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =