Skip to content

Instantly share code, notes, and snippets.

@jossmac
Created October 26, 2018 03:06
Show Gist options
  • Save jossmac/c982b962119a3337ab87327db73ad979 to your computer and use it in GitHub Desktop.
Save jossmac/c982b962119a3337ab87327db73ad979 to your computer and use it in GitHub Desktop.
Spreading objects for styles feels messy, handle it with this function instead...
// probably unnecessary but...
const merge = (...args) => args.reduce((obj, val) => ({ ...obj, ...val }), {});
const combined = merge(
{ background: 'red', padding: 20 },
{ color: 'blue' },
{ color: 'white' },
);
console.log(combined); // { background: 'red', padding: 20, color: 'white' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment