usestate nested object

Solutions on MaxInterview for usestate nested object by the best coders in the world

showing results for - "usestate nested object"
Diamond
24 Jan 2020
1const [currentApp, setCurrentApp] = useState({
2        userID: null,
3        hospitalName: null, 
4        hospitalID: null,
5        date: null,
6        time: null,
7        timestamp: null,
8        slots: 1,
9        appointmentType: null
10    })
11    
12const [appointmentType, setAppointmentType] =  useState({
13        Granulocytes: {
14            bloodType:null,
15            message: null
16        }
17})
18
19const handleGranChange = (e) => {
20        setAppointmentType({...appointmentType, Granulocytes : {
21            ...appointmentType.Granulocytes, 
22            [e.target.id] : e.target.value}
23        })
24		setCurrentApp({ ...currentApp, ['appointmentType'] : appointmentType  })
25        console.log(currentApp)
26}
Emilie
06 Jan 2018
1Syntax of using object in useState
similar questions
queries leading to this page
usestate nested object