3 ms·
This week I learned to love the spread operator. const newState = {...state, ...objectWithNewValues}
by k__ 11y ago
This week I learned to love the spread operator.
const newState = {...state, ...objectWithNewValues}
- andrewstuart2 11y agoWhoa, that works on objects/properties? I hadn't seen that before. That's nice.
- k__ 11y agoYes, here some simple examples: (state, action) => ({...state, loading: true}) (state, {error}) => ({...state, error, loading: false}) (state, {result:{data}}) => ({...state, ...data, loading: false})
- lowboy 11y agoJust keep in mind that object spread operators are a TC39 stage 1 proposal at this point.
- smrq 11y agoThat's really cool. Worth noting that it's an ES7 proposal rather than part of ES6, so you get it with Babel but not native ES6, or e.g. TypeScript.