“Copiar texto al portapapeles reactjs” Código de respuesta

reaccionar copia al portapapeles

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

React Copy al botón de portapapeles

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

reaccionar copia al portapapeles

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

Copiar texto al portapapeles reactjs

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>
  );
}
Adorable Anteater

Respuestas similares a “Copiar texto al portapapeles reactjs”

Preguntas similares a “Copiar texto al portapapeles reactjs”

Más respuestas relacionadas con “Copiar texto al portapapeles reactjs” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código