fix: Wrap props typing

This commit is contained in:
2024-04-20 12:36:11 +02:00
parent 9579dbec67
commit cd33796066

View File

@@ -1,18 +1,23 @@
import { createElement, ReactNode } from "react"; import {
ComponentPropsWithoutRef,
createElement,
ElementType,
ReactNode,
} from "react";
type Props = { type Props<T extends ElementType> = {
if?: boolean; if?: boolean;
with: Parameters<typeof createElement>[0]; with: T;
wrapperProps: Parameters<typeof createElement>[1]; wrapperProps: ComponentPropsWithoutRef<T>;
children: NonNullable<ReactNode>; children: NonNullable<ReactNode>;
}; };
export function Wrap({ export function Wrap<T extends ElementType>({
if: condition, if: condition,
with: wrapper, with: wrapper,
wrapperProps, wrapperProps,
children, children,
}: Props) { }: Props<T>) {
return condition ? ( return condition ? (
createElement(wrapper, wrapperProps, [children]) createElement(wrapper, wrapperProps, [children])
) : ( ) : (