Socket
Socket
Sign inDemoInstall

final-form-arrays

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

final-form-arrays

Array Mutators for 🏁 Final Form


Version published
Maintainers
1
Created

What is final-form-arrays?

The final-form-arrays package is an extension for Final Form that provides utilities for managing arrays in forms. It simplifies the process of handling dynamic fields, such as adding, removing, and reordering items in an array within a form.

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

Adding Items to an Array

This feature allows you to dynamically add items to an array within a form. The code sample demonstrates how to use the FieldArray component to manage a list of friends, with the ability to add new friends and remove existing ones.

const { FieldArray } = require('final-form-arrays');

<FieldArray name="friends">
  {({ fields }) => (
    <div>
      {fields.map((name, index) => (
        <div key={name}>
          <label>Friend #{index + 1}</label>
          <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>

Removing Items from an Array

This feature allows you to remove items from an array within a form. The code sample shows how to use the FieldArray component to manage a list of friends, with the ability to remove a friend by clicking a button.

const { FieldArray } = require('final-form-arrays');

<FieldArray name="friends">
  {({ fields }) => (
    <div>
      {fields.map((name, index) => (
        <div key={name}>
          <label>Friend #{index + 1}</label>
          <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>
      ))}
    </div>
  )}
</FieldArray>

Reordering Items in an Array

This feature allows you to reorder items in an array within a form. The code sample demonstrates how to use the FieldArray component to manage a list of friends, with the ability to move a friend up or down in the list.

const { FieldArray } = require('final-form-arrays');

<FieldArray name="friends">
  {({ fields }) => (
    <div>
      {fields.map((name, index) => (
        <div key={name}>
          <label>Friend #{index + 1}</label>
          <Field name={`${name}.firstName`} component="input" placeholder="First Name" />
          <Field name={`${name}.lastName`} component="input" placeholder="Last Name" />
          <span onClick={() => fields.move(index, index - 1)}>↑</span>
          <span onClick={() => fields.move(index, index + 1)}>↓</span>
        </div>
      ))}
    </div>
  )}
</FieldArray>

Other packages similar to final-form-arrays

FAQs

Package last updated on 17 Jul 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