import type { FC } from "react"; import { getConditionResult } from "./getConditionResults"; import { render } from "./render"; import type { ComponentWithConditionPropsWithFunctionChildren } from "./types"; import { _memo, _shallowFn } from "./utils"; /** A shorthand for * * ```jsx * * * { ... } * * * ``` * * The same rules apply to the child elements as with using the ` block. * * @param __namedParameters The props to pass down to the `` component, see {@link ComponentWithConditionProps} */ const WhenFn: FC = ({ condition, children }) => { const conditionResult = Boolean(getConditionResult(condition)); return conditionResult && children ? render({ children }) : null; }; export const When = _memo(WhenFn, _shallowFn); WhenFn.defaultProps = { children: null };