JSFiddle - React, Tailwind, and code Playground

HTML

<input id="input" type="text"/>
<button id="copy">Copy</button>

JavaScript

function copy() {
  var copyText = document.querySelector("#input");
  copyText.select();
  document.execCommand("copy");
}

document.querySelector("#copy").addEventListener("click", copy);