4IT580: Docs
4IT580 WebGitLab

3rd Practical Class:
Forms in React

🎯 Learning Objectives

By the end of this session, you will be able to:

🤔 The Problem: Why Do We Need Form Libraries?

What happens when you build forms with just React?

Problems with this approach:

🏗️ Building Blocks: Chakra UI Form Components

Step 1: Understanding Field Components

Chakra UI provides accessible form components that automatically handle:

*Key Components:

⚡ React Hook Form

Why React Hook Form?

Step 2: Basic React Hook Form Setup

🔒 Schema Validation with Zod

Why Schema Validation?

Instead of inline validation rules, we can define schemas that are:

Step 3: Zod Schema Definition

🧩 Bonus: Building Reusable Components

🎯 Final Exercise: Build a Complete Form

  1. Fields: First Name, Last Name, Email, Message
  2. Validation:
    • All fields are required
    • Email must be valid
    • Message must be at least 10 characters
  3. React Hook Form for form state management
  4. Zod for schema validation

📚 Additional Resources