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 :: check if function javascript 
Javascript :: jquery ajax 500 error handling 
Javascript :: hasownproperty 
Javascript :: put 0 in front of month number javascript 
Javascript :: discord.js verify 
Javascript :: youtube video regex 
Javascript :: pagination hook react 
Javascript :: how to handle all error of all router in express 
Javascript :: .sort javascript 
Javascript :: javascript - get the filename and extension from input type=file 
Javascript :: react run useeffect only once 
Javascript :: javascript remove object property 
Javascript :: 3 letter months javascript array 
Javascript :: check value exist in array javascript 
Javascript :: datetime knex 
Javascript :: how to change image source using javascript 
Javascript :: Getting Binary gap in JS 
Javascript :: simplebar react 
Javascript :: js trigger window resize 
Javascript :: js weakset 
Javascript :: angular show time ago 
Javascript :: axios x-api-key for all 
Javascript :: JavaScript HTML DOM - Changing CSS 
Javascript :: currency convertor api in javascript 
Javascript :: how to put text in the center react native 
Javascript :: how to set background colour i js inline stylel 
Javascript :: react native import svg image 
Javascript :: select2 clear fields 
Javascript :: js event preventdefault continue 
Javascript :: jest writing test 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =