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 :: how to detect if ios is in dark mode react native 
Javascript :: angular create guard 
Javascript :: javascript confirm tab close 
Javascript :: express send 401 response 
Javascript :: how to sum two var in jquery 
Javascript :: react-bootstrap navbar nav link refreshes page 
Javascript :: update nodejs ubuntu 
Javascript :: the update operation document must contain atomic operators mongodb 
Javascript :: javascript synchronous wait 
Javascript :: sum of n numbers in javascript 
Javascript :: dotenv nodejs 
Javascript :: encrypt data using SHA256 algorithm in JavaScript 
Javascript :: vue dynamic create watch 
Javascript :: discord.js pick random from array 
Javascript :: lodash filter object keys 
Javascript :: vscode regex replace only group 
Javascript :: what is the use of angularjs 
Javascript :: fetch patch method 
Javascript :: react native release apk command 
Javascript :: javascript display 2 number after comma 
Javascript :: toggle in react 
Javascript :: javascript string change character at index 
Javascript :: remove div by class name javascript 
Javascript :: javascript newline in alert 
Javascript :: add access-control-allow-origin in node js 
Javascript :: javascript validate date 
Javascript :: jquery validation submit handler 
Javascript :: DataTypes Time sequelize 
Javascript :: jquery remove focus 
Javascript :: prop-types 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =