The _.defaultTo(value, defaultValue) function from the lodash library returns the value parameter if it is not null or undefined, otherwise it returns the defaultValue parameter.
Here is an example usage of _.defaultTo:
index.tsx212 chars9 lines
In this example, the myValue variable is set to null. When the _.defaultTo function is called with myValue and the defaultValue of 'default', the function returns the defaultValue because myValue is null.
If myValue had instead been set to a non-null value, the function would have returned myValue instead.
gistlibby LogSnag