UNPKG

@gechiui/compose

Version:
21 lines 913 B
/// <reference types="react" /> /** * Higher-order component creator, creating a new component which renders if * the given condition is satisfied or with the given optional prop name. * * @example * ```ts * type Props = { foo: string }; * const Component = ( props: Props ) => <div>{ props.foo }</div>; * const ConditionalComponent = ifCondition( ( props: Props ) => props.foo.length !== 0 )( Component ); * <ConditionalComponent foo="" />; // => null * <ConditionalComponent foo="bar" />; // => <div>bar</div>; * ``` * * @param predicate Function to test condition. * * @return Higher-order component. */ declare const ifCondition: <TProps extends Record<string, any>>(predicate: (props: TProps) => boolean) => <InnerProps extends {}>(Inner: import("react").ComponentType<InnerProps>) => import("react").ComponentType<InnerProps>; export default ifCondition; //# sourceMappingURL=index.d.ts.map