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

How to set a value of nest object value in onChange event

I’m trying to set a value of nested object value for the onChange event.

const [state, setState] = useState({
            fullname: '',
            email:
            address: {
                fhbca: '',
                street: '',
                landmark: '',
                pincode: '',
            }
        });

onChange={(e) => { setState({...state, address.fhbca : e.target.value }) }} **<--**

When setting the value of address.fhbca. Using this above statement throws errors Accounts.jsx: Unexpected token, expected "," (120:100). Please correct me and suggest.
how to set a value of this address.fhbca ..?

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 need to do like this

onChange={(e) => { setState(({...state, address: {...state.address, fhbca: e.target.value} }})}}
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