Array Mutators for 🏁 Final Form
Switch branches/tags
Clone or download
Latest commit d531bb6 Aug 23, 2018

README.md

🏁 Final Form Arrays

NPM Version NPM Downloads Build Status codecov.io styled with prettier

Mutators for updating array fields in 🏁 Final Form.


Installation

npm install --save final-form-arrays

or

yarn add final-form-arrays

Usage

import { createForm } from 'final-form'
import arrayMutators from 'final-form-arrays'

// Create Form
const form = createForm({
  mutators: { ...arrayMutators },
  onSubmit
})

// push
form.mutators.push('customers', { firstName: '', lastName: '' })

// pop
const customer = form.mutators.pop('customers')

Table of Contents

Mutators

form.mutators.insert(name: string, index: number, value: any) => undefined

Inserts a value into the specified index of the array field.

form.mutators.move(name: string, from: number, to: number) => undefined

Moves a value from one index to another index in the array field.

form.mutators.pop(name: string) => any

Pops a value off the end of an array field. Returns the value.

form.mutators.push(name: string, value: any) => void

Pushes a value onto the end of an array field.

form.mutators.remove(name: string, index: number) => any

Removes a value from the specified index of the array field. Returns the removed value.

form.mutators.shift(name: string) => any

Removes a value from the beginning of the array field. Returns the value.

form.mutators.swap(name: string, indexA: number, indexB: number) => void

Swaps the position of two values in the array field.

form.mutators.update(name: string, index: number, value: any) => void

Updates a value of the specified index of the array field.

form.mutators.unshift(name: string, value: any) => void

Inserts a value onto the beginning of the array field.