UNPKG

@alessiofrittoli/react-api

Version:
43 lines (41 loc) 1.97 kB
/** * Check if the given `input` is a React ComponentType. * * @template P The props the component accepts. * * @param input The input to check. * @returns `true` if the given input is a React ComponentType, `false` otherwise. */ declare const isComponentType: <P = unknown>(input: unknown) => input is React.ComponentType<P>; /** * Check if the given `input` is a React Node. * * @param input The input to check. * @returns `true` if the given input is a React Node, `false` otherwise. */ declare const isReactNode: (input: unknown) => input is React.ReactNode; /** * Represent a `React.ReactNode` or a callable function that returns a `React.ReactNode`. * * @template T An Array defining optional arguments passed to the `children` function. */ type FunctionChildren<T extends unknown[] = []> = (React.ReactNode | ((...args: T) => React.ReactNode) | FunctionChildren<T>[]); /** * Represent a `React.ReactNode` or a callable function that returns a `React.ReactNode`. * * @template T An Array defining optional arguments passed to the `children` function. */ type RenderedFunctionChildren<T extends FunctionChildren<U>, U extends unknown[]> = (T extends FunctionChildren<U>[] ? React.ReactNode[] : React.ReactNode); /** * Render `children` which could be possible a callable function. * * @template T The `children` type which extends the `FunctionChildren<U>` interface. * @template U An Array defining optional arguments passed to the `children` function. * * @param children The `children` to render. * @param args (Optional) Arguments passed to `children` if is a function. * * @returns The rendered `children`. If `children` is a function, the result of that function is returned. */ declare const childrenFn: <T extends FunctionChildren<U>, U extends unknown[]>(children: T, ...args: U) => RenderedFunctionChildren<T, U>; export { type FunctionChildren, type RenderedFunctionChildren, childrenFn, isComponentType, isReactNode };