ReactEasy
What is Formik?
Formik is a popular React form library that manages form values, validation, touched state, errors and submission through a useFormik hook or <Formik>, <Form> and <Field> components, often paired with Yup for schema validation. It is still used in many codebases, but its development has slowed considerably and most new projects choose React Hook Form, TanStack Form or React 19 form Actions instead.
How it works
initialValues,validateorvalidationSchema(Yup), andonSubmit.- It keeps values in React state (controlled inputs), tracks
touchedanderrors, and provideshandleChange,handleBlur,isSubmitting,resetForm,setFieldValue. <Field>,<ErrorMessage>and<FieldArray>reduce boilerplate.
Strengths
- Simple mental model and good docs.
- Field arrays and nested values.
- Large ecosystem of examples.
Weaknesses
- Controlled inputs: every keystroke re-renders the form, which can be slow for large forms.
- Larger bundle than React Hook Form.
- Few releases in recent years (latest 2.4.x).
Choosing today
- React Hook Form: uncontrolled, fast, small, strong TypeScript and Zod integration.
- TanStack Form: type-safe, headless, framework-agnostic.
- React 19
<form action>+useActionState: enough for many simple forms, especially with server functions.
Interview tip
Know Formik's API if the job uses it, and be ready to compare it with React Hook Form.
Code example
tsx
1import { useFormik } from "formik";2import * as Yup from "yup";34export function NewsletterFormik() {5 const formik = useFormik({6 initialValues: { email: "", topics: [] as string[] },7 validationSchema: Yup.object({8 email: Yup.string().email("Invalid email").required("Required"),9 }),10 onSubmit: async (values, { resetForm }) => {11 await fetch("/api/newsletter", { method: "POST", body: JSON.stringify(values) });12 resetForm();13 },14 });1516 return (17 <form onSubmit={formik.handleSubmit}>18 <input19 name="email"20 value={formik.values.email}21 onChange={formik.handleChange}22 onBlur={formik.handleBlur}23 />24 {formik.touched.email && formik.errors.email && <p role="alert">{formik.errors.email}</p>}25 <button type="submit" disabled={formik.isSubmitting}>Subscribe</button>26 </form>27 );28}
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the React set.