-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
140 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# This documentation is meant to be read on [final-form.org](https://final-form.org/docs/final-form-arrays/api). Links may not work on Github.com. | ||
|
||
# API | ||
|
||
This library provides the following Final Form [mutators](/docs/final-form/types/Mutator). They are intended to mimic the array mutations available [`Array.prototype`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype) in JavaScript. | ||
|
||
The `name` argument always refers to the field to be mutated. | ||
|
||
### `form.mutators.concat` | ||
|
||
```ts | ||
(name: string, value: Array<any>) => void | ||
``` | ||
|
||
Concatenates an array at the end of the field array. | ||
|
||
### `form.mutators.insert` | ||
|
||
```ts | ||
(name: string, index: number, value: any) => void` | ||
``` | ||
|
||
Inserts a value into the specified index of the field array. | ||
|
||
### `form.mutators.move` | ||
|
||
```ts | ||
(name: string, from: number, to: number) => void | ||
``` | ||
|
||
Moves a value from one index to another index in the field array. | ||
|
||
### `form.mutators.pop` | ||
|
||
<!-- prettier-ignore --> | ||
```ts | ||
(name: string) => any | ||
``` | ||
|
||
Pops a value off the end of an field array. Returns the value. | ||
|
||
### `form.mutators.push` | ||
|
||
```ts | ||
(name: string, value: any) => void | ||
``` | ||
|
||
Pushes a value onto the end of an field array. | ||
|
||
### `form.mutators.remove` | ||
|
||
<!-- prettier-ignore --> | ||
```ts | ||
(name: string, index: number) => any | ||
``` | ||
|
||
Removes a value from the specified index of the field array. Returns the removed value. | ||
|
||
### `form.mutators.removeBatch` | ||
|
||
```ts | ||
(name: string, indexes: Array<number>) => void | ||
``` | ||
|
||
Removes the values at the specified indexes of the field array. | ||
|
||
### `form.mutators.shift` | ||
|
||
<!-- prettier-ignore --> | ||
```ts | ||
(name: string) => any | ||
``` | ||
|
||
Removes a value from the beginning of the field array. Returns the value. | ||
|
||
### `form.mutators.swap` | ||
|
||
```ts | ||
(name: string, indexA: number, indexB: number) => void | ||
``` | ||
|
||
Swaps the position of two values in the field array. | ||
|
||
### `form.mutators.unshift` | ||
|
||
```ts | ||
(name: string, value: any) => void | ||
``` | ||
|
||
Inserts a value onto the beginning of the field array. | ||
|
||
### `form.mutators.update` | ||
|
||
```ts | ||
(name: string, index: number, value: any) => void | ||
``` | ||
|
||
Updates a value of the specified index of the field array. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# This documentation is meant to be read on [final-form.org](https://final-form.org/docs/final-form-arrays/getting-started). Links may not work on Github.com. | ||
|
||
# Getting Started | ||
|
||
This library provides field array management functionality as a plugin [mutator](/docs/final-form/types/Mutator) to Final Form. | ||
|
||
## Installation | ||
|
||
```bash | ||
npm install --save final-form final-form-arrays | ||
``` | ||
|
||
or | ||
|
||
```bash | ||
yarn add final-form final-form-arrays | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
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 | ||
|
||
Check out the [API](api) to see all the mutators provided. |