Function withDefault

  • adds default value to a prop, so it can still receive a value but it now has a default one

    Type Parameters

    • PropValue

    • PropName extends string

    Parameters

    Returns Hoc<[IfThenFn<HasAllPropsFn<PropName>, [...(PropValue extends ((...args) => any)
        ? []
        : [IntersectionFn<[PropName, PropValue]>])[], SetOptionalFn<PropName>]>]>

    See

    withDefaults withFactory withOverride withOverrides

    Example

    function CardWithIcon({ content, icon }: {
    content: string;
    icon: "star" | "heart" | ...;
    }) {
    return <>...</>
    }
    const StandardCard = withDefault("icon", "star")(CardWithIcon);

    <StandardCard content="some content" />
    // is equivalent to
    <CardWithIcon icon="star" content="some content" />

    // but
    <StandardCard content="some content" icon="heart" />
    // is equivalent to
    <CardWithIcon content="some content" icon="heart" /> // it propagates the new value

Generated using TypeDoc