Forms
Overview
We use the react-hook-form library along with @hookform/resolvers to simplify the process of creating and managing forms. This setup allows for the quick development of robust forms.
Form Schema
With @hookform/resolvers, you can validate your forms using a Zod schema.
Just write the schema and use it as a resolver in the useForm
hook.
This approach not only validates your forms but also helps in creating perfectly typed forms by inferring types from the schema.
Example of setting up a form with Zod schema:
Error Handling
For error handling in forms, we use the handle-error.util.ts
utility function.
This function parses error messages, sets them to the form fields’ error states, or displays a global notification for general errors.
Usage:
Form usage
Here is an example of how you can create a form:
By following these guidelines, you can effectively build and manage forms in our application, ensuring a smooth user experience and robust form handling.