1 RN Thing a Day – Day 1: Lodash in React Native (Do You Really Need It?)
Ola Abaza

Ola Abaza @ola_1313

Joined:
Aug 8, 2024

1 RN Thing a Day – Day 1: Lodash in React Native (Do You Really Need It?)

Publish Date: Aug 4
0 0

lodash

It is a JavaScript utility library that is fully compatible with React Native. It provides a large number of helpful utility functions to make working with arrays, objects, numbers, strings, etc., easier and more consistent.

Do We Really Need Lodash?
Not always.
If you're only using one or two functions like isNumber, it's often better to write them yourself or use native JavaScript.

But for more complex operations like deep cloning, sorting, or throttling, Lodash saves time and reduces bugs.

Performance Tips

  • Lodash is huge if you import the full library. Always import specific methods like lodash/isNumber to avoid bloating your bundle.

because if you do this:

import _ from 'lodash';
Enter fullscreen mode Exit fullscreen mode

✅ It works.

❌ But it includes the entire Lodash library, even if you only use isNumber(). That adds ~70 KB+ to your bundle.

Bloating your bundle” means adding unnecessary code that's never used but still included in your final app.

This Babel plugin automatically rewrites your imports like this:
From:
import { isNumber } from 'lodash';
To:
import isNumber from 'lodash/isNumber';

Final Thoughts
Lodash is still useful just use it wisely. Import only what you need and lean on native JavaScript when possible.

Comments 0 total

    Add comment