use-form | Mantine

The @mantine/form package does not depend on any other libraries. You can use it with or without @mantine/core inputs:

All examples below use the following example use-form hook.

Form validation guide

Validation errors occur when defined validation rules were violated, initialErrors were specified in useForm properties, or validation errors were set manually.

Wrapper function for the form onSubmit and onReset event handler. The onSubmit handler accepts as a second argument a function that will be called with the errors object when validation fails.

By default, event.preventDefault() is called on the form onSubmit handler. If you want to change this behavior, you can pass the onSubmitPreventDefault option to the useForm hook. It can have the following values:

Touched & dirty guide

UseFormReturnType can be used when you want to pass the form as a prop to another component:

Recommended articles