React-hook-form: Type 'T' is not assignable to type 'Path<TFieldValues>' #11680
Unanswered
perevezencev
asked this question in
Q&A
Replies: 1 comment
-
Hi, @perevezencev You'd like to give the generic type of form value object. The type definition is difficult to read and is complicated. We can make it simpler. import React from 'react'
import { z } from "zod"
import { Control, Controller } from "react-hook-form"
export const address = z.object({
street: z.string(),
})
type FormValues<Prefix> = {
[K in keyof Prefix | string]: z.infer<typeof address>
}
type AddressProperties<Prefix> = {
control: Control<FormValues<Prefix>>,
prefix: Prefix
}
export function Address(
properties: AddressProperties<'address-1' | 'address-2'>
) {
const { control, prefix} = properties
return <Controller
control={control}
name={`addresses.${prefix}.street`}
render={() => <input />}
/>
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone! I have a code like this:
why
name
is not assignable to typePath<TFieldValues>
and how can i fix this?playground
Beta Was this translation helpful? Give feedback.
All reactions