JSFiddle - React, Tailwind, and code Playground

HTML

<input type="text" id="input">
<span id="output"></span>

JavaScript

$('#input').on('keyup', function(){
	var val = $(this).val().replace(/[ ](?!\s)/g, '-');
	$('#output').text(val);
});