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

npm react copy to clipboard

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

<button onClick={() =>  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 json download 
Javascript :: firebase authentication logout 
Javascript :: fetch bearer token 
Javascript :: remove disable attr jquery 
Javascript :: box shadow javascript style change 
Javascript :: sweet alert 2 do action on confirm 
Javascript :: jquery select radio by name 
Javascript :: javascript assign value to input using name 
Javascript :: javascript find parent with class 
Javascript :: remove item jquery 
Javascript :: jvascript number to column letter 
Javascript :: jquery on blur 
Javascript :: Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. 
Javascript :: Get Substring between two characters using javascript 
Javascript :: jquery get url 
Javascript :: asyncstorage.getallkeys 
Javascript :: go to previous page 
Javascript :: clear cookies js 
Javascript :: allow only letters in div javascript 
Javascript :: kill all node process 
Javascript :: jquery get child div 
Javascript :: Navigation timeout of 30000 ms exceeded 
Javascript :: loopback find or create 
Javascript :: console.log regex 
Javascript :: how to get today date in javascript 
Javascript :: js test letter lowercase 
Javascript :: change logo sapui5 
Javascript :: scss mute warnings 
Javascript :: create paragraphs with js in html 
Javascript :: javascript compare two arrays of objects get same elements 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =