Created
October 26, 2018 03:06
-
-
Save jossmac/c982b962119a3337ab87327db73ad979 to your computer and use it in GitHub Desktop.
Spreading objects for styles feels messy, handle it with this function instead...
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
// 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