Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
final-form
Advanced tools
🏁 Framework agnostic, high performance, subscription-based form state management
Final Form is a framework-agnostic library for managing form state in JavaScript. It provides a simple API for handling form validation, submission, and state management, making it easier to build complex forms with minimal boilerplate code.
Form State Management
Final Form provides a simple way to manage form state. The `Form` component handles the form submission, while the `Field` component is used to define form fields. The form state is managed internally and can be accessed via the `render` prop.
const { Form, Field } = require('react-final-form');
const MyForm = () => (
<Form
onSubmit={formValues => {
console.log(formValues);
}}
render={({ handleSubmit }) => (
<form onSubmit={handleSubmit}>
<Field name="firstName" component="input" placeholder="First Name" />
<Field name="lastName" component="input" placeholder="Last Name" />
<button type="submit">Submit</button>
</form>
)}
/>
);
Validation
Final Form allows you to easily add validation to your forms. The `validate` function is used to define validation rules, and it returns an object containing any validation errors. These errors are then displayed in the form.
const { Form, Field } = require('react-final-form');
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}>
<Field name="firstName" component="input" placeholder="First Name" />
<Field name="lastName" component="input" placeholder="Last Name" />
<button type="submit">Submit</button>
</form>
)}
/>
);
Field-Level Validation
Final Form supports field-level validation, allowing you to define validation rules for individual fields. The `validate` prop on the `Field` component is used to specify the validation function for that field.
const { Form, Field } = require('react-final-form');
const required = value => (value ? undefined : 'Required');
const MyForm = () => (
<Form
onSubmit={formValues => {
console.log(formValues);
}}
render={({ handleSubmit }) => (
<form onSubmit={handleSubmit}>
<Field name="firstName" component="input" placeholder="First Name" validate={required} />
<Field name="lastName" component="input" placeholder="Last Name" validate={required} />
<button type="submit">Submit</button>
</form>
)}
/>
);
Form Submission
Final Form makes it easy to handle form submission. The `onSubmit` prop on the `Form` component is used to define the submission handler, which receives the form values as an argument.
const { Form, Field } = require('react-final-form');
const MyForm = () => (
<Form
onSubmit={formValues => {
console.log('Form submitted with values:', formValues);
}}
render={({ handleSubmit }) => (
<form onSubmit={handleSubmit}>
<Field name="firstName" component="input" placeholder="First Name" />
<Field name="lastName" component="input" placeholder="Last Name" />
<button type="submit">Submit</button>
</form>
)}
/>
);
Formik is a popular form library for React that provides a higher-level API for managing form state, validation, and submission. It offers more built-in features and integrations compared to Final Form, but it is specifically designed for React applications.
React Hook Form is a performant, flexible form library for React that leverages hooks for managing form state and validation. It is known for its minimal re-renders and easy integration with existing components, making it a lightweight alternative to Final Form.
Redux Form is a form library that integrates with Redux for managing form state. It provides a robust set of features for handling complex form scenarios but can be more complex to set up and use compared to Final Form. It is suitable for applications already using Redux.
You build great forms, but do you know HOW users use your forms? Find out with Form Nerd! Professional analytics from the creator of Final Form.
💰 Hey there! Do you fancy yourself a javascript expert? Take this quiz and get offers from top tech companies! 💰
✅ Zero dependencies
✅ Framework agnostic
✅ Opt-in subscriptions - only update on the state you need!
✅ 💥 5.1k gzipped 💥
Comprehensive JS framework and UI components for building enterprise-grade web apps.
In the interest of making 🏁 Final Form the best library it can be, we'd love your thoughts and feedback.
FAQs
🏁 Framework agnostic, high performance, subscription-based form state management
The npm package final-form receives a total of 335,618 weekly downloads. As such, final-form popularity was classified as popular.
We found that final-form demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.