JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" value="" maxlength="30" name="email" id="UserName">
JavaScript
document.getElementById("UserName").onkeypress = function(e) {
if (e.which == 32) {
return false;
}
}