import { type CSSProperties, type ReactNode, isValidElement, cloneElement, useId, } from "react"; interface FormFieldProps { label: ReactNode; children: ReactNode; error?: string; required?: boolean; style?: React.CSSProperties; } export default function FormField({ label, children, error, required, style, }: FormFieldProps) { const generatedId = useId(); const childProps = isValidElement(children) ? (children.props as Record) : null; const childId = childProps?.id ? String(childProps.id) : generatedId; const childWithId = isValidElement(children) ? cloneElement(children, { id: childId } as React.Attributes) : children; return (
{childWithId} {error && {error}}
); }