Replies: 1 comment
-
Stuck like you, this only way I found is to use zod validation to coerce <form.Field name={name} mode='array'>
{(field) => {
const schema = z.array(z.any())
const validateArrayValue = schema.safeParse(field.state.value)
if (!validateArrayValue.success) {
console.error('Array expected for field.state.value')
return null
}
const value = validateArrayValue.data
return (
<div className='flex flex-col gap-4'>
{value.map((_, i: number) => (
<React.Fragment key={`${name}[${i}]`}>{children(field, i)}</React.Fragment>
))}
</div>
)
}}
</form.Field> |
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.
-
I'm trying to create a reusable component that will accept a
Field
prop and a generic data type. I'm able to achieve this with the typeField: FieldComponent<TParentData, ZodValidator>;
but if I want the field to be an array I run into a type error when doing this:Have I got something missing/wrong with my
Field
type?Beta Was this translation helpful? Give feedback.
All reactions