I work on a project in React and I have an input in a table for quantity of a product I want to buy and I can’t change the value on the web page.
If I delete value property, I can modify the value and I think I type something wrong. Cand somebody help me how to type that value property to be 1?
<input
type="text"
id={"cantitate_" + index}
value={1}
onChange={(e) => changeQuantity(e.target.value, index)}
/>
changeQuantity is a function where I try to calculate something.
>Solution :
You should be using defaultValue instead of value, since I assume from the comment that you are not implementing a controlled form:
<input
type="text"
id={"cantitate_" + index}
defaultValue={1}
onChange={(e) => changeQuantity(e.target.value, index)}
/>