How can I invoke lodash/fp get and use a default value?

In the docs you linked to, as you can see, the first argument to _.get is the object itself, not a string. If your primary object is profile, then that should be the first argument, and the second argument should be a string of the path you want.

_.get(profile, 'profile.email') refers to profile.profile.email

In /fp, _.get from lodash/fp doesn’t use defaultValue, and the solution is to use getOr, which works fine for me:

https://codesandbox.io/s/vp2opyjkl


Use _.getOr(defaultValue, path, object) from lodash/fp.

Sources:

  • https://lodash.com/docs/4.17.11#get
  • https://github.com/lodash/lodash/wiki/FP-Guide