JSFiddle - React, Tailwind, and code Playground
HTML
<textarea>test test
test test</textarea>
<textarea>test test
test test
test test test</textarea>
JavaScript
$('textarea').each(function(){
var height = $('<div style="display:none; white-space:pre" id="my-hidden-div"></div>').html($(this).val()).appendTo('body').height();
$(this).css('height',height + 'px');
$('#my-hidden-div').remove();
});