What Does This Command Do?
npm install react-hook-form zod @hookform/resolvers
This installs three npm packages that are commonly used together in React applications to build forms with clean form-state management and schema-based validation.
They each have a different responsibility:
| Package | Main responsibility |
|---|---|
react-hook-form |
Manage form state, inputs, submission, errors, touched/dirty state |
zod |
Define validation rules using schemas |
@hookform/resolvers |
Connect Zod validation to React Hook Form |
The overall architecture is:
React Form
│
▼
React Hook Form
(Form Management)
│
│ form values
▼
Zod
(Schema Validation)
│
validation result
▼
@hookform/resolvers
(Integration Layer)
│
▼
React Hook Form
│
┌─────────┴─────────┐
▼ ▼
Valid Data Errors
│ │
▼ ▼
API Call Display Error
React Hook Form officially supports external schema validation through the resolver option, and Zod is one of the supported schema libraries. React Hook Form
1. react-hook-form
npm install react-hook-form
What is it?
React Hook Form is a library for managing forms in React.
Without it, you can manage every field using useState:
const [name, setName] = useState("");
const [email, setEmail] = useState("");
const [message, setMessage] = useState("");
Then you have to manually handle:
- Input values
- Validation
- Error messages
- Submit handling
- Resetting
- Dirty state
- Touched state
- Field registration
- Form state
React Hook Form provides these capabilities through APIs such as:
useForm()
register()
handleSubmit()
formState
reset()
watch()
setValue()
getValues()
The official documentation describes useForm as the primary hook for form initialization and management. React Hook Form
2. Why Do We Need React Hook Form?
Imagine your portfolio has a Contact Me form:
Name
Email
Subject
Message
[Send Message]
Without React Hook Form:
const [name, setName] = useState("");
const [email, setEmail] = useState("");
const [subject, setSubject] = useState("");
const [message, setMessage] = useState("");
You then need to manually implement validation:
if (!name) {
// show error
}
if (!email) {
// show error
}
And email validation:
if (!email.includes("@")) {
// show error
}
React Hook Form centralizes much of this form management.
const {
register,
handleSubmit,
formState: { errors }
} = useForm();
Then:
<input {...register("name")} />
and:
<input {...register("email")} />
React Hook Form tracks those fields for you.
3. Important React Hook Form Concepts
useForm()
Creates and manages the form.
const {
register,
handleSubmit,
formState: { errors }
} = useForm();
Think of it as:
useForm()
│
├── Form values
├── Validation state
├── Error state
├── Submit handling
├── Dirty state
├── Touched state
└── Form methods
4. register()
Connects an HTML input to React Hook Form.
<input {...register("name")} />
For example:
<input
{...register("email")}
/>
Now React Hook Form knows:
Field name = email
and tracks its value.
You don't need:
const [email, setEmail] = useState("");
for a normal registered input.
React Hook Form's register API is designed to connect native inputs to its form store and event handling. React Hook Form
5. handleSubmit()
Handles form submission.
<form onSubmit={handleSubmit(onSubmit)}>
For example:
const onSubmit = (data) => {
console.log(data);
};
If the form contains:
Name: Syed
Email: syed@example.com
then:
handleSubmit(onSubmit)
can produce:
{
name: "Syed",
email: "syed@example.com"
}
6. formState
Contains information about the current form.
formState: {
errors
}
It can also provide information such as:
isDirty
isValid
isSubmitting
isSubmitted
isSubmitSuccessful
touchedFields
dirtyFields
errors
This is useful for creating professional forms.
For example:
{errors.email && (
<p>{errors.email.message}</p>
)}
7. zod
The second package is:
npm install zod
What is Zod?
Zod is a schema validation library for TypeScript and JavaScript.
Instead of putting validation rules directly into your JSX, you create a schema.
For example:
const schema = z.object({
name: z.string().min(3),
email: z.string().email(),
});
This schema says:
name
└── must be a string
└── minimum 3 characters
email
└── must be a string
└── must be a valid email
So Zod is responsible for answering:
"Is this data valid according to my rules?"
8. Why Use a Schema?
Imagine your Contact form:
Name
Email
Subject
Message
You might have these rules:
Name:
Required
Minimum 3 characters
Email:
Required
Must be valid email
Subject:
Required
Minimum 5 characters
Message:
Required
Minimum 10 characters
You could write these rules manually throughout your React code.
But Zod lets you define them in one place:
const contactSchema = z.object({
name: z
.string()
.min(3, "Name must be at least 3 characters"),
email: z
.string()
.email("Invalid email address"),
subject: z
.string()
.min(5, "Subject must be at least 5 characters"),
message: z
.string()
.min(10, "Message must be at least 10 characters"),
});
Now your validation rules are centralized.
9. Zod Is More Than Required Validation
Zod provides many validation capabilities.
For example:
String
z.string()
Minimum length
z.string().min(3)
Maximum length
z.string().max(100)
z.string().email()
URL
z.url()
Number
z.number()
Minimum number
z.number().min(18)
Maximum number
z.number().max(100)
Optional
z.string().optional()
Nullable
z.string().nullable()
Enum
z.enum(["Admin", "User"])
Array
z.array(z.string())
Object
z.object({
name: z.string(),
email: z.string().email()
})
This makes Zod particularly useful when your application has many forms and complex validation rules.
10. Zod Provides TypeScript Type Inference
This is one of the biggest advantages when using React + TypeScript.
Suppose:
const schema = z.object({
name: z.string(),
email: z.string().email(),
});
You can derive the TypeScript type from the schema:
type FormValues = z.infer<typeof schema>;
TypeScript now understands:
type FormValues = {
name: string;
email: string;
};
So you don't have to define the same structure twice.
Instead of:
const schema = ...
type FormValues = {
name: string;
email: string;
};
you can use:
const schema = ...
type FormValues = z.infer<typeof schema>;
This gives you a single source of truth for the form structure and validation.
The official React Hook Form Zod integration specifically supports this pattern. React Hook Form
11. @hookform/resolvers
Now we come to the third package:
npm install @hookform/resolvers
This package is the bridge between React Hook Form and external validation libraries.
React Hook Form itself can perform basic validation.
For example:
register("name", {
required: "Name is required",
minLength: {
value: 3,
message: "Minimum 3 characters"
}
})
But if you want to use Zod:
const schema = z.object({
name: z.string().min(3)
});
React Hook Form needs a way to communicate with Zod.
That's what:
@hookform/resolvers
does.
12. What Is a Resolver?
A resolver is essentially an adapter between React Hook Form and a validation library.
React Hook Form
│
│
▼
Resolver
│
▼
Zod
React Hook Form sends the form data to the resolver.
The resolver sends the data to Zod.
Zod validates it.
The result comes back through the resolver.
Form Data
│
▼
React Hook Form
│
▼
zodResolver()
│
▼
Zod Schema
│
├── Valid
│ │
│ ▼
│ Submit
│
└── Invalid
│
▼
Errors
The official documentation describes a resolver as the integration mechanism that validates form values against an external schema and returns values/errors to React Hook Form. React Hook Form
13. zodResolver
After installing:
@hookform/resolvers
you can import:
import { zodResolver } from "@hookform/resolvers/zod";
Notice:
@hookform/resolvers
│
└── /zod
The package contains adapters for multiple validation libraries.
For example:
@hookform/resolvers/zod
@hookform/resolvers/yup
@hookform/resolvers/joi
@hookform/resolvers/ajv
and others. React Hook Form
14. Putting All Three Packages Together
Now let's combine them.
Step 1 — Create Zod Schema
import { z } from "zod";
const schema = z.object({
name: z
.string()
.min(3, "Name must be at least 3 characters"),
email: z
.string()
.email("Enter a valid email"),
message: z
.string()
.min(10, "Message must be at least 10 characters"),
});
Zod is responsible for the rules.
Step 2 — Create TypeScript Type
type FormValues = z.infer<typeof schema>;
Now TypeScript understands:
{
name: string;
email: string;
message: string;
}
Step 3 — Connect Zod to React Hook Form
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
const {
register,
handleSubmit,
formState: { errors }
} = useForm<FormValues>({
resolver: zodResolver(schema)
});
The important part is:
resolver: zodResolver(schema)
This means:
"React Hook Form, use this Zod schema whenever you validate this form."
15. Complete Example
Here is a realistic React + TypeScript example:
import { useForm } from "react-hook-form";
import { z } from "zod";
import { zodResolver } from "@hookform/resolvers/zod";
const contactSchema = z.object({
name: z
.string()
.min(3, "Name must be at least 3 characters"),
email: z
.string()
.email("Please enter a valid email address"),
message: z
.string()
.min(10, "Message must be at least 10 characters"),
});
type ContactFormValues = z.infer<typeof contactSchema>;
export default function Contact() {
const {
register,
handleSubmit,
formState: { errors }
} = useForm<ContactFormValues>({
resolver: zodResolver(contactSchema)
});
const onSubmit = (data: ContactFormValues) => {
console.log(data);
};
return (
<form onSubmit={handleSubmit(onSubmit)}>
<div>
<label>Name</label>
<input
type="text"
{...register("name")}
/>
{errors.name && (
<p>{errors.name.message}</p>
)}
</div>
<div>
<label>Email</label>
<input
type="email"
{...register("email")}
/>
{errors.email && (
<p>{errors.email.message}</p>
)}
</div>
<div>
<label>Message</label>
<textarea
{...register("message")}
/>
{errors.message && (
<p>{errors.message.message}</p>
)}
</div>
<button type="submit">
Send Message
</button>
</form>
);
}
16. Complete Flow of This Code
Suppose the user enters:
Name: Sy
Email: abc
Message: Hi
and clicks:
[Send Message]
The flow is:
User clicks Submit
│
▼
handleSubmit()
│
▼
React Hook Form
│
▼
zodResolver(contactSchema)
│
▼
Zod validates the data
│
├── name → "Sy" → INVALID
│
├── email → "abc" → INVALID
│
└── message → "Hi" → INVALID
│
▼
Validation Errors
│
▼
formState.errors
│
▼
Display error messages
Therefore:
Name:
Name must be at least 3 characters
Email:
Please enter a valid email address
Message:
Message must be at least 10 characters
onSubmit() is not called with valid submission data until validation succeeds.
17. What Happens When Data Is Valid?
Suppose the user enters:
Name:
Syed
Email:
syed@example.com
Message:
I want to contact you.
Then:
Submit
│
▼
React Hook Form
│
▼
zodResolver
│
▼
Zod
│
▼
Valid
│
▼
handleSubmit()
│
▼
onSubmit(data)
Then:
const onSubmit = (data) => {
console.log(data);
};
receives:
{
name: "Syed",
email: "syed@example.com",
message: "I want to contact you."
}
Now you can call your API:
const onSubmit = async (data: ContactFormValues) => {
await axios.post(
`${environment.apiUrl}/messages`,
data
);
};
18. Why Not Just Use React Hook Form Validation?
React Hook Form already supports validation.
For example:
<input
{...register("name", {
required: "Name is required",
minLength: {
value: 3,
message: "Minimum 3 characters"
}
})}
/>
This works.
So why use Zod?
Because as your application grows, validation can become complex.
For example:
User Registration
Login
Contact
Profile
Project
Experience
Skill
Article
Category
Tag
Admin User
You may have many validation rules.
With Zod:
const userSchema = z.object({
name: z.string().min(3),
email: z.string().email(),
age: z.number().min(18),
});
The validation rules become centralized and reusable.
19. React Hook Form vs Zod
These two libraries are not competitors.
They solve different problems.
| React Hook Form | Zod |
|---|---|
| Manages forms | Validates data |
| Tracks fields | Defines schemas |
| Handles submission | Checks data |
| Tracks errors | Produces validation issues |
| Tracks dirty state | Provides type inference |
| Tracks touched state | Validates complex structures |
Provides register() |
Provides z.object() |
Think:
React Hook Form
=
Form Manager
and:
Zod
=
Validation Engine
20. What Does @hookform/resolvers Add?
It connects them.
┌─────────────────────┐
│ React Hook Form │
│ │
│ Form management │
│ Submission │
│ Field state │
│ Error state │
└──────────┬──────────┘
│
│ Resolver
▼
┌─────────────────────┐
│ Zod │
│ │
│ Validation rules │
│ Schema │
│ Type inference │
└─────────────────────┘
Without the resolver:
React Hook Form Zod
separate systems
With:
resolver: zodResolver(schema)
they work together.
21. Why zodResolver() Instead of Just schema?
You might wonder why we don't write:
useForm({
schema: contactSchema
});
React Hook Form expects external schema validation through its resolver mechanism.
Therefore:
useForm({
resolver: zodResolver(contactSchema)
});
The resolver converts Zod's validation result into the error/value format that React Hook Form understands. React Hook Form
22. Important: register() vs Zod Validation
You may see two different styles.
Style 1 — React Hook Form validation
register("name", {
required: "Name is required",
minLength: {
value: 3,
message: "Minimum 3 characters"
}
});
Style 2 — Zod validation
const schema = z.object({
name: z
.string()
.min(3, "Minimum 3 characters")
});
When using:
resolver: zodResolver(schema)
you generally want the validation rules to live in the Zod schema, rather than duplicating them in register. The official Zod integration recommends keeping validation rules in the schema. React Hook Form
So prefer:
<input {...register("name")} />
with:
const schema = z.object({
name: z.string().min(3)
});
rather than duplicating the same rule in both places.
23. TypeScript + Zod + React Hook Form
This combination is especially powerful.
const schema = z.object({
name: z.string(),
email: z.string().email(),
});
Then:
type FormValues = z.infer<typeof schema>;
Then:
useForm<FormValues>({
resolver: zodResolver(schema)
});
You now have:
Zod Schema
│
├──────────────┐
▼ ▼
Validation TypeScript
Type
│ │
└──────┬───────┘
▼
React Hook Form
This significantly reduces duplication between validation and TypeScript types.
24. A Very Important Number Input Example
HTML inputs can produce values as strings.
For example:
<input type="number" {...register("age")} />
The browser may give React Hook Form:
"25"
rather than:
25
But your Zod schema may expect:
z.number()
This creates a type mismatch.
The official Zod integration recommends using valueAsNumber or Zod coercion for this situation. React Hook Form
For example:
<input
type="number"
{...register("age", {
valueAsNumber: true
})}
/>
Now:
Browser
│
│ "25"
▼
React Hook Form
│
│ 25
▼
Zod
│
▼
z.number()
Alternatively, Zod can coerce:
age: z.coerce.number()
25. Server/API Validation Is Still Required
This is extremely important for your React + ASP.NET Core architecture.
React validation is not a security boundary.
For example:
React
│
│ Zod validation
▼
ASP.NET Core API
│
│ Server validation
▼
Database
You should still validate data in your ASP.NET Core API.
For example:
React + Zod
│
│ User experience
│ Fast feedback
▼
ASP.NET Core API
│
│ Security / business rules
│ Authoritative validation
▼
SQL Server
A malicious client can bypass your React application and call your API directly.
Therefore:
Frontend validation
+
Backend validation
is the correct architecture.
26. React Hook Form + Zod + ASP.NET Core
For your portfolio project, a typical flow would be:
React 19
│
│ User enters form data
▼
React Hook Form
│
│ Manage form
▼
Zod
│
│ Validate
▼
zodResolver
│
│ Valid?
│
├── No ──► Display errors
│
└── Yes
│
▼
Axios
│
│ HTTP POST
▼
ASP.NET Core Web API
│
▼
Server Validation
│
▼
Application Layer
│
▼
EF Core
│
▼
SQL Server
This is a very reasonable industry-style approach for a TypeScript React application.
27. npm install Explained
Now let's break down the actual command:
npm install react-hook-form zod @hookform/resolvers
npm
Node Package Manager.
It manages JavaScript/TypeScript packages.
install
Tells npm:
Download and install these packages into my project.
react-hook-form
Installs:
React Hook Form
for form management.
zod
Installs:
Zod
for schema validation.
@hookform/resolvers
Installs:
React Hook Form Resolvers
which provides the integration adapters.
28. What Happens Inside node_modules?
After running:
npm install react-hook-form zod @hookform/resolvers
npm installs the packages into:
node_modules/
and updates:
package.json
Your package.json will contain dependencies similar to:
{
"dependencies": {
"@hookform/resolvers": "...",
"react-hook-form": "...",
"zod": "..."
}
}
The exact versions depend on what npm resolves at installation time.
29. Why Are These Three Packages Commonly Installed Together?
Because they form a clean three-layer combination:
┌───────────────────────────┐
│ React UI / JSX │
└─────────────┬─────────────┘
│
▼
┌───────────────────────────┐
│ React Hook Form │
│ Form Management │
└─────────────┬─────────────┘
│
▼
┌───────────────────────────┐
│ @hookform/resolvers │
│ Integration Adapter │
└─────────────┬─────────────┘
│
▼
┌───────────────────────────┐
│ Zod │
│ Schema Validation │
└───────────────────────────┘
Each library has a clear responsibility.
30. Are These Packages Industry Standard?
Yes, this is a very common and professional combination for React + TypeScript applications.
React Hook Form has official integration documentation for Zod, and @hookform/resolvers officially supports Zod and many other schema-validation libraries. React Hook Form
For a React 19 + TypeScript application, this stack is a strong choice when you need forms with meaningful validation.
31. When Should You Use This Combination?
Use it when you have forms such as:
Login
Registration
Contact
Profile
Change Password
Create Project
Edit Project
Create Skill
Edit Skill
Create Experience
Edit Experience
Create Article
Edit Article
Create Category
Edit Category
Especially when the form contains:
- Multiple fields
- Validation rules
- Conditional validation
- Complex objects
- Arrays
- Numeric values
- Email/URL validation
- Reusable forms
- TypeScript
- API submission
32. When Might You Not Need It?
For a very simple form:
Search: [___________] [Search]
you probably don't need all three packages.
You could simply use:
const [search, setSearch] = useState("");
Similarly, a single checkbox or simple input doesn't necessarily justify a form library.
The value becomes much clearer when the form has multiple fields and validation requirements.
33. The Most Important Things to Remember
react-hook-form
↓
Manages the form
zod
↓
Defines validation rules
@hookform/resolvers
↓
Connects Zod with React Hook Form
And:
resolver: zodResolver(schema)
is the key integration point.
Final Mental Model
Think about a restaurant analogy:
React Hook Form
│
└── Waiter
Manages the order/form
Zod
│
└── Rule checker
Checks whether the order is valid
@hookform/resolvers
│
└── Translator
Connects the waiter with the rule checker
In technical terms:
FORM
│
▼
React Hook Form
Form Management
│
▼
zodResolver()
Integration
│
▼
Zod
Schema Validation
│
┌─────┴─────┐
▼ ▼
Valid Invalid
│ │
▼ ▼
API Call Errors
So, in one sentence:
react-hook-formmanages the form,zoddefines and performs schema validation, and@hookform/resolversconnects Zod to React Hook Form.