I want that my input value which has type number changes on every keystroke in react but it does not work. I have two inputs one with type text and one with type number. with every keystroke I call a function and setState with the value of input and I use the two-way binding to give back the input value the updated state. with input type text everything works fine but not with input type number the input value changes after input lo. here is my code
const IngredientForm = (props) => {
const [name, setName] = useState("");
const [amount, setAmount] = useState("");
const nameChangeHandler = (event) => {
setName(event.target.value);
};
const amountChangeHandler = (event) => {
setAmount(event.target.value);
};
const submitHandler = (event) => {
event.preventDefault();
// ...
};
return (
<section className="ingredient-form">
<Card>
<form onSubmit={submitHandler}>
<div className="form-control">
<label htmlFor="title">Name</label>
<input
type="text"
id="title"
onChange={nameChangeHandler}
value={name}
/>
</div>
<div className="form-control">
<label htmlFor="amount">Amount</label>
<input
type="number"
id="amount"
onChange={amountChangeHandler}
value={amount}
/>
</div>
<div className="ingredient-form__actions">
<button type="submit">Add Ingredient</button>
</div>
</form>
</Card>
</section>
);
};
export default IngredientForm;
Update: Actually I can not see the value change when I try to use browser Inspect and see value change in element tab otherwise If I log something with every keystroke It just work fine