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

im trying to useState and put in it multiple values from user input

I’m trying to use state and put in it multiple values from user input but when l insert new values the rest of the useState object turns to undefined
first textbox

all text box

the code
input code

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

l don’t understand why does it turn to undefined after moving and typing in another input text box and when l send it to the API to save it in the database some values register as undefined

error code

>Solution :

That happens because

(e) => setBook({name: e.target.value})

overwrites the current value.
You can instead do

(e) => setBook((book) => ({...book, name: e.target.value}))

to merge everything from the existing object and the new name.

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