Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can't edit input value in React

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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)}
  />
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading