Skip to content

Commit b826e98

Browse files
authored
Documented and Typed fields.value (#96)
1 parent 71e8da3 commit b826e98

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ Updates a value of the specified index of the array field.
279279

280280
A function to add a value to the beginning of the array.
281281

282+
#### `fields.value: any[]`
283+
284+
The value of the array. Should be treated as readonly.
285+
282286
#### `meta.active?: boolean`
283287

284288
[See the 🏁 Final Form docs on `active`](https://github.com/final-form/final-form#active-boolean).

src/FieldArray.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,28 @@ describe('FieldArray', () => {
682682
expect(getByTestId('values')).toHaveTextContent('')
683683
})
684684

685+
it('should provide value', () => {
686+
const renderArray = jest.fn(() => <div />)
687+
render(
688+
<Form
689+
onSubmit={onSubmitMock}
690+
mutators={arrayMutators}
691+
subscription={{}}
692+
initialValues={{ foo: ['a', 'b', 'c'] }}
693+
>
694+
{() => (
695+
<form>
696+
<FieldArray name="foo">{renderArray}</FieldArray>
697+
</form>
698+
)}
699+
</Form>
700+
)
701+
expect(renderArray).toHaveBeenCalled()
702+
expect(renderArray).toHaveBeenCalledTimes(1)
703+
704+
expect(renderArray.mock.calls[0][0].fields.value).toEqual(['a', 'b', 'c'])
705+
})
706+
685707
// it('should respect record-level validation', () => {
686708
// // https://github.com/final-form/react-final-form-arrays/pull/84
687709
// const { getByTestId, getByText } = render(

src/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface FieldArrayRenderProps<FieldValue, T extends HTMLElement> {
1717
shift: () => FieldValue
1818
swap: (indexA: number, indexB: number) => void
1919
unshift: (value: FieldValue) => void
20+
value: FieldValue[]
2021
} & FieldState<FieldValue[]>
2122
meta: Partial<{
2223
// TODO: Make a diff of `FieldState` without all the functions

src/types.js.flow

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export type FieldArrayRenderProps = {
3434
remove: (index: number) => any,
3535
shift: () => any,
3636
swap: (indexA: number, indexB: number) => void,
37-
unshift: (value: any) => void
37+
unshift: (value: any) => void,
38+
value: any[]
3839
},
3940
meta: Meta
4041
}

0 commit comments

Comments
 (0)