JSFiddle - React, Tailwind, and code Playground
HTML
<form>
<label>MaxLengthSample</label>
<input id="hoge" type="text" maxlength=3 />
</form>
JavaScript
const inputForm = document.getElementById("hoge");
const maxLength = parseInt(inputForm.getAttribute("maxLength"), 10);
let prevValue = '';
inputForm.addEventListener('input', function(e) {
const inputValue = e.target.value;
if (inputValue.length > maxLength) {
e.target.value = prevValue;
} else {
prevValue = inputValue;
}
});