JSFiddle - React, Tailwind, and code Playground
by Emil Guareno
HTML
<input type="text" id="user-input" />
<div id="user-text"></div>
JavaScript
function convertSpacesToNbsp(str){
return str.split('').map(function(char){
if(char === ' '){
char = ' ';
}
return char;
}).join('');
}
$(document).on('keyup', '#user-input', function(event){
var userText = $('#user-text');
var inputStr = $(this).val().toUpperCase();
var clientText = convertSpacesToNbsp(inputStr);
userText.html(clientText);
});