Last active
October 26, 2018 15:29
-
-
Save islam3zzat/2385842b638aba97f7268b8f5a3f550a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
function updateUserName(user, { firstName, lastName }) { | |
const { name } = user; | |
const newName = { | |
firstName: firstName || name.firstName, | |
lastName: lastName || name.lastName, | |
}; | |
return { ...user, name: newName }; | |
} | |
const updatedUser = updateUserName(user, { lastName: 'new last name' }); | |
// finally we need to call `saveUser` to actually update our data store, check `users` before | |
console.log(users); | |
users = saveUser(users, updatedUser) | |
// now check again |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment