React + React Hook Form
Performant React forms with Zod or Yup validation. This page shows exactly what pickstack adds to a React project for React Hook Form: the packages, the new files and the changes to existing ones. Every combination is installed, built, linted and tested in CI.
$ npm create pickstack@latest my-app -- --framework react --modules react-hook-form --yesCustomize in the configurator
Packages it adds
| Package | Version | Type |
|---|---|---|
@hookform/resolvers | ^7.0.9 | runtime |
react-hook-form | ^7.92.0 | runtime |
zod | ^4.6.7 | runtime |
New files
import { zodResolver } from "@hookform/resolvers/zod";
import { useState } from "react";
import { useForm } from "react-hook-form";
import { z } from "zod";
const schema = z.object({
email: z.email("Enter a valid email address."),
});
export default function SignupForm() {
const [joined, setJoined] = useState("");
const {
register,
handleSubmit,
formState: { errors },
} = useForm<z.infer<typeof schema>>({
resolver: zodResolver(schema),
defaultValues: { email: "" },
});
if (joined) return <p className="text">Thanks, {joined} is on the list.</p>;
return (
<form
noValidate
className="form"
onSubmit={handleSubmit((values) => setJoined(values.email))}
>
<label className="field">
Email
<input type="email" className="input" {...register("email")} />
{errors.email && (
<span role="alert" className="error">
{errors.email.message}
</span>
)}
</label>
<button type="submit" className="btn">
Sign up
</button>
</form>
);
}
Changes to existing files
import Counter from "./components/Counter";+import SignupForm from "./components/SignupForm"; export default function App() { return ( <main className="app"> <h1 className="title">my-app</h1> <Counter />+ <SignupForm /> </main> ); }⋯ 1 unchanged lines
⋯ 87 unchanged lines background: #334155; } +.form {+ display: flex;+ width: 100%;+ max-width: 24rem;+ flex-direction: column;+ gap: 0.75rem;+}+ +.field {+ display: flex;+ flex-direction: column;+ gap: 0.25rem;+ font-size: 0.875rem;+ font-weight: 500;+}+ +.input {+ border: 1px solid #cbd5e1;+ border-radius: 0.5rem;+ padding: 0.5rem 0.75rem;+ font: inherit;+}+ +.error {+ color: #dc2626;+ font-weight: 400;+}+
Project files
.gitignoreREADME.mdindex.htmlpackage.jsonsrc/App.tsxsrc/components/Counter.tsxsrc/components/SignupForm.tsxsrc/index.csssrc/main.tsxtsconfig.jsonvite.config.ts