defaultTo
defaultTo uses a fallback value when a Spot resolves to null or undefined. Without it, you’d build the same shape by hand:
// without defaultToconst userName = shape(fetchUser.result.name, (name) => name ?? "Guest")// with defaultToconst userName = defaultTo(fetchUser.result.name, "Guest")
// without defaultToconst userName = shape( { name: fetchUser.result.name, fallback: defaultName.value }, ({ name, fallback }) => name ?? fallback,)// with defaultToconst userName = defaultTo(fetchUser.result.name, defaultName.value)Arguments
Section titled “Arguments”spot: Spot<T>— the source Spot.fallback: P | Spot<P>— a fallback value, or a Spot that provides it.
Returns
Section titled “Returns”Spot<NonNullable<T> | P> — the source value when it is not null or undefined; otherwise, the fallback value.