DEV Community

Discussion on: You Might Not Need Lodash

Collapse
 
stevealee profile image
SteveALee

You can also use mutlple sources in the RHS of a spead expression to get a merge

Collapse
 
antjanus profile image
Antonin J. (they/them) • Edited

do you mean like this?

const mergedObj = { ...obj1, ...obj2 };

My only issue with it is that it doesn't recursively merge. It's fine for flat objects. I use this pattern pretty often at work, sometimes in conjunction with lodash.

For instance, I use Objection for ORM and it has "computed properties" that need to be accessed in order to get the value, they're not serialized when doing toJSON so I often resort to:

res.send({ ...someModel, ..._.pick(someModel, ['computedProperty1', 'computedProp2']);

EDIT Totally forgot, this is a pretty common pattern in Redux!

Collapse
 
stevealee profile image
SteveALee

Completely agree. Its shallow like Object.assign. I was just say is an alternative to it really.