Reading this answer I came up with this code but did not work. What am I missing?
function App() {
const [value, setValue] = useState();
function onChange(e) {
const re = /^[0-9\b]+$/;
if (e.target.value === "" || re.test(e.target.value)) {
setValue(e.target.value);
}
}
return <input value={value} onChange={onChange} />;
}
render(<App />, document.getElementById("root"));