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

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

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
152K
decreased by-18.8%
Maintainers
1
Weekly downloads
 
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 01 Dec 2017

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