Hacker News new | ask | show | jobs
by k__ 3966 days ago
This week I learned to love the spread operator.

    const newState = {...state, ...objectWithNewValues}
2 comments

That'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.
Whoa, that works on objects/properties? I hadn't seen that before. That's nice.
Just keep in mind that object spread operators are a TC39 stage 1 proposal at this point.
Yes, here some simple examples:

    (state, action) => ({...state, loading: true})

    (state, {error}) => ({...state, error, loading: false})

    (state, {result:{data}}) => ({...state, ...data, loading: false})