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);

inputForm.addEventListener('input', function(e) {
	const inputValue = e.target.value;
	if (inputValue.length > maxLength) {
		e.target.value = inputValue.slice(0, maxLength);
	}
});