This content originally appeared on DEV Community and was authored by Benjamin Black
Given the announcement of "The Future of Lodash", with Lodash joining OpenJS, I thought I'd express my ongoing love for Lodash and share one of the many reasons why it is still useful for me day-to-day.
TL;DR Merge is an unsung hero of the library.
In the absence of something like Immer, if you need to immutably update a deeply-nested object, you can do this:
const properties = { /* ... */ };
setTracks((prev) => ({
...prev,
[trackId]: {
...prev[trackId],
points: {
...prev[trackId].points,
[pointId]: {
...prev[trackId].points[pointId],
properties: {
...prev[trackId].points[pointId].properties,
...properties,
}
}
}
}
}));
Or you can do this:
setTracks((prev) =>
merge({}, prev, {[routeId]: {points: {[pointId]: {properties}}}}))
);
This content originally appeared on DEV Community and was authored by Benjamin Black
Benjamin Black | Sciencx (2025-10-23T15:04:08+00:00) The Present of Lodash. Retrieved from https://www.scien.cx/2025/10/23/the-present-of-lodash/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.