@@ -152,6 +152,7 @@ export function useFormik<Values extends FormikValues = FormikValues>({
152
152
const initialTouched = React . useRef ( props . initialTouched || emptyTouched ) ;
153
153
const initialStatus = React . useRef ( props . initialStatus ) ;
154
154
const isMounted = React . useRef < boolean > ( false ) ;
155
+ const validated = React . useRef < boolean > ( false ) ;
155
156
const fieldRegistry = React . useRef < FieldRegistry > ( { } ) ;
156
157
if ( __DEV__ ) {
157
158
// eslint-disable-next-line react-hooks/rules-of-hooks
@@ -314,6 +315,7 @@ export function useFormik<Values extends FormikValues = FormikValues>({
314
315
props . validationSchema ? runValidationSchema ( values ) : { } ,
315
316
props . validate ? runValidateHandler ( values ) : { } ,
316
317
] ) . then ( ( [ fieldErrors , schemaErrors , validateErrors ] ) => {
318
+ validated . current = true ;
317
319
const combinedErrors = deepmerge . all < FormikErrors < Values > > (
318
320
[ fieldErrors , schemaErrors , validateErrors ] ,
319
321
{ arrayMerge }
@@ -949,15 +951,18 @@ export function useFormik<Values extends FormikValues = FormikValues>({
949
951
) ;
950
952
951
953
const isValid = React . useMemo (
952
- ( ) =>
953
- typeof isInitialValid !== 'undefined'
954
- ? dirty
955
- ? state . errors && Object . keys ( state . errors ) . length === 0
956
- : isInitialValid !== false && isFunction ( isInitialValid )
957
- ? ( isInitialValid as ( props : FormikConfig < Values > ) => boolean ) ( props )
958
- : ( isInitialValid as boolean )
959
- : state . errors && Object . keys ( state . errors ) . length === 0 ,
960
- [ isInitialValid , dirty , state . errors , props ]
954
+ ( ) => {
955
+ if ( ! validated . current && validateOnMount ) return false
956
+ if ( typeof isInitialValid !== 'undefined' ) {
957
+ if ( dirty ) return state . errors && Object . keys ( state . errors ) . length === 0 ;
958
+
959
+ return isInitialValid !== false && isFunction ( isInitialValid )
960
+ ? ( isInitialValid as ( props : FormikConfig < Values > ) => boolean ) ( props )
961
+ : ( isInitialValid as boolean )
962
+ }
963
+ return state . errors && Object . keys ( state . errors ) . length === 0
964
+ } ,
965
+ [ isInitialValid , dirty , state . errors , props , validated . current ]
961
966
) ;
962
967
963
968
const ctx = {
0 commit comments