@@ -8,6 +8,7 @@ import componentTypes from '../component-types';
88import { prepareArrayValidator , getValidate } from './validator-helpers' ;
99import composeValidators from './compose-validators' ;
1010import isEqual from 'lodash/isEqual' ;
11+ import get from 'lodash/get' ;
1112
1213const calculateInitialValue = ( props ) => {
1314 if ( Object . prototype . hasOwnProperty . call ( props , 'initialValue' ) && props . dataType ) {
@@ -88,6 +89,10 @@ const useFieldApi = ({ name, resolveProps, skipRegistration = false, ...props })
8889 const { validatorMapper, formOptions } = useContext ( RendererContext ) ;
8990 const [ warning , setWarning ] = useState ( ) ;
9091
92+ // if there is field initial value, we have to check form initialValues
93+ // initialValues should have higher priority
94+ const formInitialValue = Object . prototype . hasOwnProperty . call ( props , 'initialValue' ) ? get ( formOptions . initialValues , name ) : undefined ;
95+
9196 const resolvedProps = resolveProps ? resolveProps ( props , createFieldProps ( name , formOptions ) , formOptions ) || { } : { } ;
9297
9398 const combinedProps = { ...props , ...resolvedProps } ;
@@ -112,7 +117,7 @@ const useFieldApi = ({ name, resolveProps, skipRegistration = false, ...props })
112117 ...( stateValidate ? { validate : stateValidate } : { } ) ,
113118 } ;
114119
115- const field = useField ( name , enhancedProps ) ;
120+ const field = useField ( name , { ... enhancedProps , ... ( typeof formInitialValue !== 'undefined' && { initialValue : formInitialValue } ) } ) ;
116121
117122 /** Reinitilize type */
118123 useEffect ( ( ) => {
0 commit comments