Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-final-form

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-final-form

🏁 High performance subscription-based form state management for React

  • 6.5.9
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
274K
decreased by-17.66%
Maintainers
1
Weekly downloads
 
Created

What is react-final-form?

react-final-form is a framework-agnostic form state management library for React. It provides a simple and flexible way to manage form state, validation, and submission handling in React applications.

What are react-final-form's main functionalities?

Form State Management

This feature allows you to manage the state of your form fields. The code sample demonstrates a simple form with two fields, 'firstName' and 'lastName', and a submit button. The form state is managed and displayed in real-time.

const MyForm = () => (
  <Form
    onSubmit={formValues => {
      console.log(formValues);
    }}
    render={({ handleSubmit, form, submitting, pristine, values }) => (
      <form onSubmit={handleSubmit}>
        <div>
          <label>First Name</label>
          <Field name="firstName" component="input" type="text" placeholder="First Name" />
        </div>
        <div>
          <label>Last Name</label>
          <Field name="lastName" component="input" type="text" placeholder="Last Name" />
        </div>
        <div>
          <button type="submit" disabled={submitting || pristine}>
            Submit
          </button>
        </div>
        <pre>{JSON.stringify(values, 0, 2)}</pre>
      </form>
    )}
  />
);

Field-Level Validation

This feature allows you to add validation to individual fields. The code sample shows how to add a 'required' validation to the 'firstName' and 'lastName' fields.

const required = value => (value ? undefined : 'Required');

const MyForm = () => (
  <Form
    onSubmit={formValues => {
      console.log(formValues);
    }}
    render={({ handleSubmit }) => (
      <form onSubmit={handleSubmit}>
        <div>
          <label>First Name</label>
          <Field name="firstName" component="input" type="text" placeholder="First Name" validate={required} />
        </div>
        <div>
          <label>Last Name</label>
          <Field name="lastName" component="input" type="text" placeholder="Last Name" validate={required} />
        </div>
        <div>
          <button type="submit">
            Submit
          </button>
        </div>
      </form>
    )}
  />
);

Form-Level Validation

This feature allows you to add validation to the entire form. The code sample demonstrates how to validate the 'firstName' and 'lastName' fields at the form level.

const validate = values => {
  const errors = {};
  if (!values.firstName) {
    errors.firstName = 'Required';
  }
  if (!values.lastName) {
    errors.lastName = 'Required';
  }
  return errors;
};

const MyForm = () => (
  <Form
    onSubmit={formValues => {
      console.log(formValues);
    }}
    validate={validate}
    render={({ handleSubmit }) => (
      <form onSubmit={handleSubmit}>
        <div>
          <label>First Name</label>
          <Field name="firstName" component="input" type="text" placeholder="First Name" />
        </div>
        <div>
          <label>Last Name</label>
          <Field name="lastName" component="input" type="text" placeholder="Last Name" />
        </div>
        <div>
          <button type="submit">
            Submit
          </button>
        </div>
      </form>
    )}
  />
);

Other packages similar to react-final-form

FAQs

Package last updated on 01 Apr 2022

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc