Function withDefaults

  • adds default values to many props, so they can still receive values but they now have a default

    Type Parameters

    • Map extends Record<string, unknown>

    Parameters

    Returns Hoc<[WithDefaultsFn<ToSchema<Map>>]>

    See

    withDefault withFactory withOverrides withOverride

    Example

    function Card({ content, icon, border }: {
    content: string;
    icon: "star" | "heart" | ...;
    border: "none" | "dashed" | ...
    }) {
    return <>...</>
    }
    const StandardCard = withDefaults({icon: "star", border: "rounded"})(Card);

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

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

Generated using TypeDoc