Skip to content

Instantly share code, notes, and snippets.

@sebmarkbage
Created May 30, 2014 23:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebmarkbage/005c81e6f2f5ddac443f to your computer and use it in GitHub Desktop.
Save sebmarkbage/005c81e6f2f5ddac443f to your computer and use it in GitHub Desktop.
Deep Immutable Mutation Using Spread Operator
// Mutative
company.users.push({ name: 'New User' });
return company;
// Immutable
return { ...company, users: [ ...company.users, { name: 'New User' } ] };
// Implicit identifier
return { ...company, users: [ ... , { name: 'New User' } ] };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment