Wrapping Up the Forms Tutorial
By now, you should be comfortable with not only rendering forms in React but also utilizing React Hook Form for data management.
You've also learnt how to use Zod for data validation and four distinct ways to send data to the server:
- Sending a JSON payload to an API endpoint
- Sending a form data payload to an API endpoint
- Sending a data object to a server action
- Sending a form data object to another server action.
The choice of which method to use ultimately depends on the needs of your application.
What's even more impressive is the minimal use of TypeScript in our implementation!
While we did employ a bit of typing on the properties of the components, the core functionality of TypeScript was primarily handled by z.infer
. This handy function generated the TypeScript type from the Zod schema. Remarkably, the Zod schema itself did not contain any TypeScript types.
Armed with this knowledge, you should be ready to start building your next forms in a JS environment.
Enjoy the process, and don't be afraid to explore and experiment!