Reputation: 845
const [fee, setFee] = useState({newPatient:'',establishedPatient:''})
const field1='newPatient'
const field2='establishedPatient'
I want to update the fee object properties. Property name should be taken from variables (field1,field 2)
onChangeText={(val)=>setFee({...fee,newPatient:val})}. //Working
onChangeText={(val)=>setFee({...fee,...fee[field1]=val})} //Here I'm using field 1 variable to get the property name and its not working
Upvotes: 0
Views: 392
Reputation: 13588
This is what you want
onChangeText={(val)=>setFee({...fee, [field1]: val })}
Upvotes: 2