-
I'm using I want to write a function that dynamically creates the // Comp.tsx
import validationRules from './validation.ts'
function Comp() {
const fields: Field[] = ...
const form = useForm({
...
validation: validationRules(fields)
})
}
// validation.ts
function createRules(fields: Field[]) {
return fields.reduce((acc, field) => {
if (field.type === 'boolean') {
acc[field.name] = (value: boolean) => typeof value === "boolean" ? null : 'invalid type'
} else {
acc[field.name] = isNotEmpty()
}
return acc
},
{} // <-- typescript needs a type in here
)
} Thanks |
Beta Was this translation helpful? Give feedback.
Answered by
rtivital
May 6, 2024
Replies: 1 comment 4 replies
-
I do not understand what you need from the |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you really need this, use
UseFormInput
type from@mantine/form
package. To learn how to use it, see https://github.com/mantinedev/mantine/blob/master/packages/%40mantine/form/src/types.ts