Socket
Socket
Sign inDemoInstall

formik

Package Overview
Dependencies
15
Maintainers
1
Versions
211
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    formik

Build forms in React, without the tears


Version published
Weekly downloads
2.5M
increased by2.61%
Maintainers
1
Install size
4.22 MB
Created
Weekly downloads
Β 

Package description

What is formik?

Formik is a popular open-source library for building forms in React and React Native. It helps with handling form state, validation, and submission. Formik provides a simple and efficient way to create controlled form components with less boilerplate code.

What are formik's main functionalities?

Form State Management

Formik simplifies form state management by providing 'initialValues' to set up the form state and 'onSubmit' to handle form submission.

{"<Formik initialValues={{ name: '' }} onSubmit={(values) => { console.log(values); }}><Form><Field name='name' type='text' /><button type='submit'>Submit</button></Form></Formik>"}

Validation and Error Handling

Formik provides a 'validate' function to define custom validation logic and uses 'ErrorMessage' to display validation errors.

{"<Formik initialValues={{ email: '' }} validate={values => { const errors = {}; if (!values.email) { errors.email = 'Required'; } else if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(values.email)) { errors.email = 'Invalid email address'; } return errors; }} onSubmit={(values, { setSubmitting }) => { setTimeout(() => { alert(JSON.stringify(values, null, 2)); setSubmitting(false); }, 400); }}><Form><Field name='email' type='email' /><ErrorMessage name='email' component='div' /><button type='submit'>Submit</button></Form></Formik>"}

Integration with Yup for Schema Validation

Formik can be integrated with Yup, a schema builder for value parsing and validation, to simplify form validation using a schema.

{"<Formik initialValues={{ email: '' }} validationSchema={Yup.object({ email: Yup.string().email('Invalid email address').required('Required'), })} onSubmit={(values, { setSubmitting }) => { setTimeout(() => { alert(JSON.stringify(values, null, 2)); setSubmitting(false); }, 400); }}><Form><Field name='email' type='email' /><ErrorMessage name='email' /><button type='submit'>Submit</button></Form></Formik>"}

Custom Input Components

Formik allows the use of custom input components with the 'as' prop in the 'Field' component, enabling the creation of reusable form elements.

{"<Formik initialValues={{ name: '' }} onSubmit={(values) => { console.log(values); }}><Form><Field name='name' as={MyCustomInput} /><button type='submit'>Submit</button></Form></Formik>"}

Other packages similar to formik

Readme

Source

Formik.js

Build forms in React, without the tears.


Stable Release Blazing Fast gzip size license Discord

Visit https://formik.org to get started with Formik.

Organizations and projects using Formik

List of organizations and projects using Formik

Authors

Contributing

This monorepo uses yarn, so to start you'll need the package manager installed.

To run E2E tests you'll also need Playwright set up, which can be done locally via npx playwright install. Afterward, run yarn start:app and in a separate tab run yarn e2e:ui to boot up the test runner.

When you're done with your changes, we use changesets to manage release notes. Run yarn changeset to autogenerate notes to be appended to your pull request.

Thank you!

Contributors

Formik is made with <3 thanks to these wonderful people (emoji key):


Jared Palmer

πŸ’¬ πŸ’» 🎨 πŸ“– πŸ’‘ πŸ€” πŸ‘€ ⚠️

Ian White

πŸ’¬ πŸ› πŸ’» πŸ“– πŸ€” πŸ‘€

Andrej Badin

πŸ’¬ πŸ› πŸ“–

Adam Howard

πŸ’¬ πŸ› πŸ€” πŸ‘€

Vlad Shcherbin

πŸ’¬ πŸ› πŸ€”

Brikou CARRE

πŸ› πŸ“–

Sam Kvale

πŸ› πŸ’» ⚠️

Jon Tansey

πŸ› πŸ’»

Tyler Martinez

πŸ› πŸ“–

Tobias Lohse

πŸ› πŸ’»

This project follows the all-contributors specification. Contributions of any kind welcome!

  • TSDX - Zero-config CLI for TypeScript used by this repo. (Formik's Rollup configuration as a CLI)

Apache 2.0 License.

Keywords

FAQs

Last updated on 17 Sep 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc