React & Modern Frontend (445 Qs)•Part 8: Advanced React Patterns, Portals & Performance (152 - 261)
What is formik?
Formik is a small react form library that helps you with the three major problems,
- Getting values in and out of form state
- Validation and error messages
- Handling form submission
Practical Code Example
jsx
// Formik: Form state management library
import { Formik, Form, Field } from 'formik';
function LoginForm() {
return (
<Formik initialValues={{ email: '' }} onSubmit={values => console.log(values)}>
<Form>
<Field name="email" type="email" />
<button type="submit">Login</button>
</Form>
</Formik>
);
}