I’m looking to pass an object with lots of variables from the parent to child.
For example,I want to pass Person to the child
Person: firstName,lastName, dateOfBirth, nationality, phone, address (nested)
Address: firstLine,secondLine, zip,state, country
What is the recommended way of approaching this out of the two approaches below?
child({person,updatePerson})
vs
child({firstName,updateFirstName,lastName, updateLastName..etc})
This issue I have with passing the object is that it breaks encapsulation and you need to be careful around copying the object. However, the alternative becomes quite cumbersome to include the property and an update method for each propetty.
e.g.
function onUpdateZip(zip){
newPerson={...person};
newAddress={...person.address};
newPerson.address=newAddress;
newAddress.zip=zip;
updatePerson(newPerson);
}
vs
function onUpdateZip(zip){
updateZip(zip);
}