You don't need Lodash
And I reckon you shouldn't use it.
Everything you can do in Lodash, you can do just as well in ES6 either entirely (isArray, map) or with a basic repeatable pattern (groupBy, sortBy, distinct).
You're better off learning and using the patterns of the language you're using, rather than learning the characteristics of a library and dealing with the bundle size, license, security, and maintenance implications. On the other hand, the language syntax is here to stay, and language familiarity applies to every project that uses it (especially in a landscape like React).
Not only does it make you a more versatile JS/TS developer, but using the language makes it easier for other developers with experience with the language to get up to speed. You're never going to find someone who is familiar with all of the libraries you use, but it's relatively easy to find someone with experience in the language.
Not using Lodash also saves you a lot in bundle size. If you're importing the entire library, it's 70KB. That's half of the entire React library. And even if you're going through the trouble of importing per function (how much time did you spend on doing this btw?), you're still getting a lot more than you bargained for ([1 (see FAQ)], [2]). And importing per function is yet another thing you'll have to teach your developers and enforce in PRs, especially since hardly any other libraries require this nowadays.
Some of the patterns to replace Lodash might initially seem more complex, but with daily use, you'll quickly start recognizing them at a glance. Think sumBy(items, item => item.value)
vs items.reduce((total, item) => total + item, 0)
. And by leveraging the language itself, you can easily chain filter(x)
, map(y)
, and sort(z)
in a more readable and maintainable manner.
This gist isn't even just about Lodash. This applies to most libraries that have usable native alternatives. Another such example is Axios, and a less obvious example is redux-observables, which just happens to be abandoned as well (another risk).
Reconsider every single package you use. Do you really need the overhead?
That's the gist of my thoughts on using libraries like Lodash. Let me know what you think.