Correct way to import lodash

Bill picture Bill · Feb 7, 2016 · Viewed 172.4k times · Source

I had a pull request feedback below, just wondering which way is the correct way to import lodash?

You'd better do import has from 'lodash/has'.. For the earlier version of lodash (v3) which by itself is pretty heavy, we should only import a specidic module/function rather than importing the whole lodash library. Not sure about the newer version (v4).

import has from 'lodash/has';

vs

import { has } from 'lodash';

Thanks

Answer

Bill picture Bill · Feb 7, 2016

import has from 'lodash/has'; is better because lodash holds all it's functions in a single file, so rather than import the whole 'lodash' library at 100k, it's better to just import lodash's has function which is maybe 2k.