JSFiddle - React, Tailwind, and code Playground

HTML

<textarea class="expand" rows="1"></textarea>

CSS

.expand {
    overflow-y: hidden;
}

JavaScript

$('.expand').on('keydown', function(e) {
    if(13==(e.keyCode ? e.keyCode : e.which)) {
        var rows = $(this).attr('rows');
        var rowsNew = parseInt(rows) + 1;
        $(this).attr('rows', rowsNew);
    }
});
$('.expand').on('keyup', function (e) {
    var lines = $('.expand').val().match(/\n/g);
    var need = lines ? lines.length + 1 : 1;
    var itis = $('.expand').attr("rows");
    if(itis!=need) {
        $('.expand').attr("rows", need);
    }
});