JSFiddle - React, Tailwind, and code Playground

HTML

<textarea id="zzzzz" cols="30" rows="10">
  Hello toster
</textarea>
<button id="btn">pew</button>

JavaScript

btn.onclick = ()=>{
  zzzzz.select();
  document.execCommand("copy");
}