Skip to content

Instantly share code, notes, and snippets.

@islam3zzat
Last active October 26, 2018 15:29
Show Gist options
  • Save islam3zzat/2385842b638aba97f7268b8f5a3f550a to your computer and use it in GitHub Desktop.
Save islam3zzat/2385842b638aba97f7268b8f5a3f550a to your computer and use it in GitHub Desktop.
// ...
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