JSFiddle - React, Tailwind, and code Playground
HTML
<textarea cols='100' rows='20'></textarea>
JavaScript
$( document ).on( 'change', 'textarea', function() {
$( this ).val( $( this ).val().replace( /\n/g, ' ' ).replace( /\s{4}?/g, ' ' ).replace( /\s{3}?/g, ' ' ).replace( /\s{2}?/g, ' ' ) );
});