import { ComponentType } from "react"; import { DependencyNames } from "../types/DependencyNames"; import { Fn, IntersectionFn, ToSchema } from "../types/Fn"; import { Hoc } from "../types/Hoc"; interface WithIfFn extends Fn { return: [PropName, any] extends this["arg0"] ? this["arg0"] : this["arg0"] | [PropName, PropValue]; } interface WithIfHoc { (propName: PropName, options?: { Else?: ComponentType; }): Hoc<[WithIfFn]>; = DependencyNames>(factory: (props: DependencyProps) => any, options: { Else?: ComponentType; dependencyNames: TDependencyNames; }): Hoc<[IntersectionFn>]>; } /** * renders conditionally * * @experimental It could have a better name * * @example * const AdminDashboard: React.FC = () => { * return <>... * } * const SafeAdminDashboard = withIf<"isAdmin", boolean>("isAdmin")(AdminDashboard) * * // renders * * * // renders null * * * @example * const HappyScreen: React.FC = () => { * return <>... * } * const BlueErrorScreen: React.FC = () => { * return <>... * } * const NewComponent = withIf("error", { * Else: BlueErrorScreen * })(HappyScreen) * * // renders * * * // renders * * * @example * type HappinessLevel = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10; * const HappyScreen: React.FC = () => { * return <>... * } * const SadScreen: React.FC = () => { * return <>... * } * const MoodScreen = withIf<{ happinessLevel: HappinessLevel }>( * ({ happinessLevel }) => happinessLevel >= 5, * { * dependencyNames: ["happinessLevel"], * Else: SadScreen, * }, * )(HappyScreen); * * // renders * * * // renders * */ export declare const withIf: WithIfHoc; export {}; //# sourceMappingURL=withIf.d.ts.map