diff --git a/README.md b/README.md index 6ace9bf..d35077e 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,8 @@ const MyForm = () => ( - [`component?: React.ComponentType`](#component-reactcomponenttypefieldarrayrenderprops) - [`name: string`](#name-string) - [`render?: (props: FieldArrayRenderProps) => React.Node`](#render-props-fieldarrayrenderprops--reactnode) + - [`defaultValue?: any`](#defaultvalue-any) + - [`initialValue?: any`](#initialvalue-any) - [`isEqual?: (allPreviousValues: Array, allNewValues: Array) => boolean`](#isequal-allpreviousvalues-arrayany-allnewvalues-arrayany--boolean) - [`subscription?: FieldSubscription`](#subscription-fieldsubscription) - [`validate?: (value: ?any[], allValues: Object) => ?any`](#validate-value-any-allvalues-object--any) @@ -200,6 +202,16 @@ A render function that is given [`FieldArrayRenderProps`](#fieldarrayrenderprops), as well as any non-API props passed into the `` component. +#### `defaultValue?: any` + +⚠️ You probably want `initialValue`! ⚠️ + +_**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)!**_ + +#### `initialValue?: any` + +[See the 🏁 Final Form docs on `initialValue`](https://github.com/final-form/final-form#initialvalue-any) + #### `isEqual?: (allPreviousValues: Array, allNewValues: Array) => boolean` 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. diff --git a/src/FieldArray.js b/src/FieldArray.js index a8d8b5a..e952beb 100644 --- a/src/FieldArray.js +++ b/src/FieldArray.js @@ -17,12 +17,16 @@ const versions = { const FieldArray = ({ name, subscription, + defaultValue, + initialValue, isEqual, validate, ...rest }: FieldArrayProps) => { const { fields, meta } = useFieldArray(name, { subscription, + defaultValue, + initialValue, isEqual, validate }) diff --git a/src/types.js.flow b/src/types.js.flow index 1c5da1a..05b6517 100644 --- a/src/types.js.flow +++ b/src/types.js.flow @@ -48,6 +48,8 @@ export type RenderableProps = $Shape<{ export type UseFieldArrayConfig = { subscription?: FieldSubscription, + defaultValue?: any, + initialValue?: any, isEqual?: (any[], any[]) => boolean, validate?: (value: ?(any[]), allValues: Object, meta: ?FieldState) => ?any } diff --git a/src/useFieldArray.js b/src/useFieldArray.js index 84863bb..d516b76 100644 --- a/src/useFieldArray.js +++ b/src/useFieldArray.js @@ -16,6 +16,8 @@ const useFieldArray = ( name: string, { subscription = all, + defaultValue, + initialValue, isEqual = defaultIsEqual, validate: validateProp }: UseFieldArrayConfig = {} @@ -58,6 +60,8 @@ const useFieldArray = ( ...fieldState } = useField(name, { subscription: { ...subscription, length: true }, + defaultValue, + initialValue, isEqual, validate, format: v => v