How to have working TypeScript type-checking when extract form fields into components #11497
-
Hey, I'm having issue with extracting form fields to separate components. If I have a form field directly inside a form, types pass but after extracting types do not pass. I created a simplified codesandbox of the issue: https://codesandbox.io/p/sandbox/react-hook-form-nested-fields-example-v2-9w7gj9 Code is in App.tsx. Inside I've tried to search an example that would do this but have not found any from the official website or from Github.com. How should I type things to make it work? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
function FormFields({
control,
}: {
control: Control<FormFieldInputs>;
}) {
// Type error happens here
const { field } = useController({ name: "example", control });
return <input {...field} />;
} |
Beta Was this translation helpful? Give feedback.
Control
is the generic type so you can fill the type argument with form value type.