UNPKG

react-with-hoc

Version:

Work with React and HOCs (Higher-Order Components)

31 lines 1.17 kB
import { Fn, FromSchema, IntersectionFn, Pipe, SetOptionalFn } from "../types/Fn"; import { Hoc } from "../types/Hoc"; interface WithSpreadFn<PropName extends string, Names extends string> extends Fn { return: Pipe<this["arg0"], [ IntersectionFn<[ PropName, FromSchema<Extract<this["arg0"], [Names, any]>> ]>, SetOptionalFn<Names> ]>; } interface WithSpreadHoc { <PropName extends string, Names extends string>(propName: PropName): Hoc<[WithSpreadFn<PropName, Names>]>; } /** * Start receiving an object and spread all properties to Component * * @experimental It uses the same mechanism as {@link withDefaults} but it could also have the same mechanism as {@link withOverrides} * * @example * function Profile({ name, age, city }: {...}) { * ... * } * const NewProfile = withSpread<"profile", "name" | "age" | "city">("profile")(Profile) * <NewProfile profile={{ name: "Some Name", age: 20, city: "Some City" }} /> * // is equivalent to * <Profile name="Some Name" age={20} city="Some City" /> */ export declare const withSpread: WithSpreadHoc; export {}; //# sourceMappingURL=withSpread.d.ts.map