Function withWrapper

  • Wraps the component with the provided Component Wrapper

    Type Parameters

    • const WrapperProps

    • const PickOptions extends string[] = [never]

    • const OmitOptions extends string[] = [never]

    Parameters

    • Wrapper: ComponentType<WrapperProps>
    • Optional options: {
          omitProps?: undefined;
          pickProps: PickOptions;
      } | {
          omitProps: OmitOptions;
          pickProps?: undefined;
      }

    Returns PickOptions extends [never]
        ? OmitOptions extends [never]
            ? Hoc<[]>
            : Hoc<[IntersectionFn<Exclude<ToSchema<WrapperProps>, ["children" | OmitOptions[number], any]>>]>
        : Hoc<[IntersectionFn<Extract<Exclude<ToSchema<WrapperProps>, ["children", any]>, [PickOptions[number], any]>>]>

    Example

    const NewComponent = withWrapper(Wrapper)(Component)
    <NewComponent a="a" b="b" c="c" />
    // is equivalent to
    <Wrapper> // by default, it does not bring any prop
    <Component a="a" b="b" c="c" />
    </Wrapper>

    Example

    const NewComponent = withWrapper(Wrapper, { pickProps: ['a', 'b'] })(Component)
    <NewComponent a="a" b="b" c="c" />
    // is equivalent to
    <Wrapper a="a" b="b">
    <Component a="a" b="b" c="c" />
    </Wrapper>

    Example

    const NewComponent = withWrapper(Wrapper, { omitProps: ['a', 'b'] })(Component)
    <NewComponent a="a" b="b" c="c" />
    // is equivalent to
    <Wrapper c="c">
    <Component a="a" b="b" c="c" />
    </Wrapper>

    Example

    // to carry all props, use omitProps with empty array
    const NewComponent = withWrapper(Wrapper, { omitProps: [] })(Component)
    <NewComponent a="a" b="b" c="c" />
    // is equivalent to
    <Wrapper a="a" b="b" c="c">
    <Component a="a" b="b" c="c" />
    </Wrapper>

Generated using TypeDoc