"use client"; import { ReactNode } from "react"; import { FieldPath, FieldValues, RegisterOptions, useFormContext, UseFormRegisterReturn, } from "react-hook-form"; import { WithRHFError } from "./WithRHFError.js"; type Props< TValues extends FieldValues, TFieldName extends FieldPath = FieldPath, > = { name: TFieldName; rules?: RegisterOptions; children: (props: UseFormRegisterReturn) => ReactNode; }; // Helper component for various react-hook-form connected components. export function FormInput< TValues extends FieldValues, TFieldName extends FieldPath = FieldPath, >({ name, rules, children }: Props) { const formContext = useFormContext(); if (!formContext) { throw new Error("FormInput must be used within a FormProvider"); } const { register } = formContext; return ( name={name}> {children(register(name, rules))} ); } /* Usage example: * * * {(props) => } * */