Correct way to import lodash

后端 未结 5 1190
梦谈多话
梦谈多话 2020-12-04 07:10

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\'.. F

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-04 07:42

    You can import them as

    import {concat, filter, orderBy} from 'lodash';
    

    or as

    import concat from 'lodash/concat';
    import orderBy from 'lodash/orderBy';
    import filter from 'lodash/filter';
    

    the second one is much optimized than the first because it only loads the needed modules

    then use like this

    pendingArray: concat(
                        orderBy(
                            filter(payload, obj => obj.flag),
                            ['flag'],
                            ['desc'],
                        ),
                        filter(payload, obj => !obj.flag),
    

提交回复
热议问题