JSFiddle - React, Tailwind, and code Playground

HTML

<textarea id="text"></textarea>
<input type="button" id="hi">

JavaScript

function typeInTextarea(el, newText) {
  var start = el.selectionStart
  var end = el.selectionEnd
  var text = el.value
  var before = text.substring(0, start)
  var after  = text.substring(end, text.length)
  el.value = (before + newText + after)
  el.selectionStart = el.selectionEnd = start + newText.length
  el.focus()
}

document.getElementById('hi').onclick = function() {
   typeInTextarea(document.getElementById('text'), "You clicked the clickable click button and it was inserted!");
}