JSFiddle - React, Tailwind, and code Playground

HTML

<textarea cols="60" rows="2">try to add
a newline here</textarea>

JavaScript

var t = document.querySelector("textarea");
t.oninput = function(){
    this.rows = this.value.split(/\n/g).length;
};