Mutators for updating array fields in π Final Form.
npm install --save final-form-arrays
or
yarn add final-form-arrays
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')
- Mutators
form.mutators.insert(name: string, index: number, value: any) => undefined
form.mutators.move(name: string, from: number, to: number) => undefined
form.mutators.pop(name: string) => any
form.mutators.push(name: string, value: any) => void
form.mutators.remove(name: string, index: number) => any
form.mutators.shift(name: string) => any
form.mutators.swap(name: string, indexA: number, indexB: number) => void
form.mutators.update(name: string, index: number, value: any) => void
form.mutators.unshift(name: string, value: any) => void
Inserts a value into the specified index of the array field.
Moves a value from one index to another index in the array field.
Pops a value off the end of an array field. Returns the value.
Pushes a value onto the end of an array field.
Removes a value from the specified index of the array field. Returns the removed value.
Removes a value from the beginning of the array field. Returns the value.
Swaps the position of two values in the array field.
Updates a value of the specified index of the array field.
Inserts a value onto the beginning of the array field.