Skip to content

Commit 16f19c5

Browse files
PerfectPixelerikras
authored andcommitted
Add defaultValue and initialValue (#98)
1 parent 638d825 commit 16f19c5

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ const MyForm = () => (
9797
- [`component?: React.ComponentType<FieldArrayRenderProps>`](#component-reactcomponenttypefieldarrayrenderprops)
9898
- [`name: string`](#name-string)
9999
- [`render?: (props: FieldArrayRenderProps) => React.Node`](#render-props-fieldarrayrenderprops--reactnode)
100+
- [`defaultValue?: any`](#defaultvalue-any)
101+
- [`initialValue?: any`](#initialvalue-any)
100102
- [`isEqual?: (allPreviousValues: Array<any>, allNewValues: Array<any>) => boolean`](#isequal-allpreviousvalues-arrayany-allnewvalues-arrayany--boolean)
101103
- [`subscription?: FieldSubscription`](#subscription-fieldsubscription)
102104
- [`validate?: (value: ?any[], allValues: Object) => ?any`](#validate-value-any-allvalues-object--any)
@@ -200,6 +202,16 @@ A render function that is given
200202
[`FieldArrayRenderProps`](#fieldarrayrenderprops), as well as any non-API props
201203
passed into the `<FieldArray/>` component.
202204

205+
#### `defaultValue?: any`
206+
207+
⚠️ You probably want `initialValue`! ⚠️
208+
209+
_**Before using this prop, read and understand the 🏁 Final Form documentation on [`initialValue`](https://github.com/final-form/final-form#initialvalue-any) and [`defaultValue`](https://github.com/final-form/final-form#defaultvalue-any)!**_
210+
211+
#### `initialValue?: any`
212+
213+
[See the 🏁 Final Form docs on `initialValue`](https://github.com/final-form/final-form#initialvalue-any)
214+
203215
#### `isEqual?: (allPreviousValues: Array<any>, allNewValues: Array<any>) => boolean`
204216

205217
A function that can be used to compare two arrays of values (before and after every change) and calculate pristine/dirty checks. Defaults to a function that will `===` check each element of the array.

src/FieldArray.js

+4
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@ const versions = {
1717
const FieldArray = ({
1818
name,
1919
subscription,
20+
defaultValue,
21+
initialValue,
2022
isEqual,
2123
validate,
2224
...rest
2325
}: FieldArrayProps) => {
2426
const { fields, meta } = useFieldArray(name, {
2527
subscription,
28+
defaultValue,
29+
initialValue,
2630
isEqual,
2731
validate
2832
})

src/types.js.flow

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export type RenderableProps<T> = $Shape<{
4848

4949
export type UseFieldArrayConfig = {
5050
subscription?: FieldSubscription,
51+
defaultValue?: any,
52+
initialValue?: any,
5153
isEqual?: (any[], any[]) => boolean,
5254
validate?: (value: ?(any[]), allValues: Object, meta: ?FieldState) => ?any
5355
}

src/useFieldArray.js

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const useFieldArray = (
1616
name: string,
1717
{
1818
subscription = all,
19+
defaultValue,
20+
initialValue,
1921
isEqual = defaultIsEqual,
2022
validate: validateProp
2123
}: UseFieldArrayConfig = {}
@@ -58,6 +60,8 @@ const useFieldArray = (
5860
...fieldState
5961
} = useField(name, {
6062
subscription: { ...subscription, length: true },
63+
defaultValue,
64+
initialValue,
6165
isEqual,
6266
validate,
6367
format: v => v

0 commit comments

Comments
 (0)