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

react-final-form-arrays

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-final-form-arrays

A component for rendering and editing arrays 🏁 React Final Form

  • 3.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
179K
increased by4.44%
Maintainers
1
Weekly downloads
 
Created

What is react-final-form-arrays?

The react-final-form-arrays package is an extension for react-final-form that provides utilities for managing arrays in forms. It simplifies the process of adding, removing, and manipulating array fields within a form, making it easier to handle dynamic form fields.

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

Adding and Removing Fields

This feature allows you to dynamically add and remove fields in a form. The code sample demonstrates how to use the FieldArray component to manage an array of 'friends' with first and last names.

```jsx
import React from 'react';
import { FieldArray } from 'react-final-form-arrays';
import { Form, Field } from 'react-final-form';

const MyForm = () => (
  <Form
    onSubmit={formValues => console.log(formValues)}
    render={({ handleSubmit }) => (
      <form onSubmit={handleSubmit}>
        <FieldArray name="friends">
          {({ fields }) => (
            <div>
              {fields.map((name, index) => (
                <div key={name}>
                  <Field name={`${name}.firstName`} component="input" placeholder="First Name" />
                  <Field name={`${name}.lastName`} component="input" placeholder="Last Name" />
                  <span onClick={() => fields.remove(index)}>-</span>
                </div>
              ))}
              <button type="button" onClick={() => fields.push({})}>Add Friend</button>
            </div>
          )}
        </FieldArray>
        <button type="submit">Submit</button>
      </form>
    )}
  />
);

export default MyForm;
```

Conditional Rendering of Array Fields

This feature allows for conditional rendering of array fields. The code sample shows how to conditionally render a remove button for each friend field, only if the index is greater than 0.

```jsx
import React from 'react';
import { FieldArray } from 'react-final-form-arrays';
import { Form, Field } from 'react-final-form';

const MyForm = () => (
  <Form
    onSubmit={formValues => console.log(formValues)}
    render={({ handleSubmit }) => (
      <form onSubmit={handleSubmit}>
        <FieldArray name="friends">
          {({ fields }) => (
            <div>
              {fields.map((name, index) => (
                <div key={name}>
                  <Field name={`${name}.firstName`} component="input" placeholder="First Name" />
                  <Field name={`${name}.lastName`} component="input" placeholder="Last Name" />
                  {index > 0 && <span onClick={() => fields.remove(index)}>-</span>}
                </div>
              ))}
              <button type="button" onClick={() => fields.push({})}>Add Friend</button>
            </div>
          )}
        </FieldArray>
        <button type="submit">Submit</button>
      </form>
    )}
  />
);

export default MyForm;
```

Other packages similar to react-final-form-arrays

FAQs

Package last updated on 28 May 2019

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