{"ast":null,"code":"import { Children, createContext, useContext, useRef, useEffect, useReducer, useCallback, useMemo, useImperativeHandle, createElement, useLayoutEffect, forwardRef, Component } from 'react';\nimport isEqual from 'react-fast-compare';\nimport deepmerge from 'deepmerge';\nimport isPlainObject from 'lodash-es/isPlainObject';\nimport clone from 'lodash-es/clone';\nimport toPath from 'lodash-es/toPath';\nimport invariant from 'tiny-warning';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport cloneDeep from 'lodash-es/cloneDeep';\n\nfunction _extends() {\n _extends = Object.assign || function (target) {\n for (var i = 1; i < arguments.length; i++) {\n var source = arguments[i];\n\n for (var key in source) {\n if (Object.prototype.hasOwnProperty.call(source, key)) {\n target[key] = source[key];\n }\n }\n }\n\n return target;\n };\n\n return _extends.apply(this, arguments);\n}\n\nfunction _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass.__proto__ = superClass;\n}\n\nfunction _objectWithoutPropertiesLoose(source, excluded) {\n if (source == null) return {};\n var target = {};\n var sourceKeys = Object.keys(source);\n var key, i;\n\n for (i = 0; i < sourceKeys.length; i++) {\n key = sourceKeys[i];\n if (excluded.indexOf(key) >= 0) continue;\n target[key] = source[key];\n }\n\n return target;\n}\n\nfunction _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}\n/** @private is the value an empty array? */\n\n\nvar isEmptyArray = function isEmptyArray(value) {\n return Array.isArray(value) && value.length === 0;\n};\n/** @private is the given object a Function? */\n\n\nvar isFunction = function isFunction(obj) {\n return typeof obj === 'function';\n};\n/** @private is the given object an Object? */\n\n\nvar isObject = function isObject(obj) {\n return obj !== null && typeof obj === 'object';\n};\n/** @private is the given object an integer? */\n\n\nvar isInteger = function isInteger(obj) {\n return String(Math.floor(Number(obj))) === obj;\n};\n/** @private is the given object a string? */\n\n\nvar isString = function isString(obj) {\n return Object.prototype.toString.call(obj) === '[object String]';\n};\n/** @private is the given object a NaN? */\n// eslint-disable-next-line no-self-compare\n\n\nvar isNaN$1 = function isNaN(obj) {\n return obj !== obj;\n};\n/** @private Does a React component have exactly 0 children? */\n\n\nvar isEmptyChildren = function isEmptyChildren(children) {\n return Children.count(children) === 0;\n};\n/** @private is the given object/value a promise? */\n\n\nvar isPromise = function isPromise(value) {\n return isObject(value) && isFunction(value.then);\n};\n/** @private is the given object/value a type of synthetic event? */\n\n\nvar isInputEvent = function isInputEvent(value) {\n return value && isObject(value) && isObject(value.target);\n};\n/**\r\n * Same as document.activeElement but wraps in a try-catch block. In IE it is\r\n * not safe to call document.activeElement if there is nothing focused.\r\n *\r\n * The activeElement will be null only if the document or document body is not\r\n * yet defined.\r\n *\r\n * @param {?Document} doc Defaults to current document.\r\n * @return {Element | null}\r\n * @see https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/core/dom/getActiveElement.js\r\n */\n\n\nfunction getActiveElement(doc) {\n doc = doc || (typeof document !== 'undefined' ? document : undefined);\n\n if (typeof doc === 'undefined') {\n return null;\n }\n\n try {\n return doc.activeElement || doc.body;\n } catch (e) {\n return doc.body;\n }\n}\n/**\r\n * Deeply get a value from an object via its path.\r\n */\n\n\nfunction getIn(obj, key, def, p) {\n if (p === void 0) {\n p = 0;\n }\n\n var path = toPath(key);\n\n while (obj && p < path.length) {\n obj = obj[path[p++]];\n }\n\n return obj === undefined ? def : obj;\n}\n/**\r\n * Deeply set a value from in object via it's path. If the value at `path`\r\n * has changed, return a shallow copy of obj with `value` set at `path`.\r\n * If `value` has not changed, return the original `obj`.\r\n *\r\n * Existing objects / arrays along `path` are also shallow copied. Sibling\r\n * objects along path retain the same internal js reference. Since new\r\n * objects / arrays are only created along `path`, we can test if anything\r\n * changed in a nested structure by comparing the object's reference in\r\n * the old and new object, similar to how russian doll cache invalidation\r\n * works.\r\n *\r\n * In earlier versions of this function, which used cloneDeep, there were\r\n * issues whereby settings a nested value would mutate the parent\r\n * instead of creating a new object. `clone` avoids that bug making a\r\n * shallow copy of the objects along the update path\r\n * so no object is mutated in place.\r\n *\r\n * Before changing this function, please read through the following\r\n * discussions.\r\n *\r\n * @see https://github.com/developit/linkstate\r\n * @see https://github.com/jaredpalmer/formik/pull/123\r\n */\n\n\nfunction setIn(obj, path, value) {\n var res = clone(obj); // this keeps inheritance when obj is a class\n\n var resVal = res;\n var i = 0;\n var pathArray = toPath(path);\n\n for (; i < pathArray.length - 1; i++) {\n var currentPath = pathArray[i];\n var currentObj = getIn(obj, pathArray.slice(0, i + 1));\n\n if (currentObj && (isObject(currentObj) || Array.isArray(currentObj))) {\n resVal = resVal[currentPath] = clone(currentObj);\n } else {\n var nextPath = pathArray[i + 1];\n resVal = resVal[currentPath] = isInteger(nextPath) && Number(nextPath) >= 0 ? [] : {};\n }\n } // Return original object if new value is the same as current\n\n\n if ((i === 0 ? obj : resVal)[pathArray[i]] === value) {\n return obj;\n }\n\n if (value === undefined) {\n delete resVal[pathArray[i]];\n } else {\n resVal[pathArray[i]] = value;\n } // If the path array has a single element, the loop did not run.\n // Deleting on `resVal` had no effect in this scenario, so we delete on the result instead.\n\n\n if (i === 0 && value === undefined) {\n delete res[pathArray[i]];\n }\n\n return res;\n}\n/**\r\n * Recursively a set the same value for all keys and arrays nested object, cloning\r\n * @param object\r\n * @param value\r\n * @param visited\r\n * @param response\r\n */\n\n\nfunction setNestedObjectValues(object, value, visited, response) {\n if (visited === void 0) {\n visited = new WeakMap();\n }\n\n if (response === void 0) {\n response = {};\n }\n\n for (var _i = 0, _Object$keys = Object.keys(object); _i < _Object$keys.length; _i++) {\n var k = _Object$keys[_i];\n var val = object[k];\n\n if (isObject(val)) {\n if (!visited.get(val)) {\n visited.set(val, true); // In order to keep array values consistent for both dot path and\n // bracket syntax, we need to check if this is an array so that\n // this will output { friends: [true] } and not { friends: { \"0\": true } }\n\n response[k] = Array.isArray(val) ? [] : {};\n setNestedObjectValues(val, value, visited, response[k]);\n }\n } else {\n response[k] = value;\n }\n }\n\n return response;\n}\n\nvar FormikContext = /*#__PURE__*/createContext(undefined);\nFormikContext.displayName = 'FormikContext';\nvar FormikProvider = FormikContext.Provider;\nvar FormikConsumer = FormikContext.Consumer;\n\nfunction useFormikContext() {\n var formik = useContext(FormikContext);\n !!!formik ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"Formik context is undefined, please verify you are calling useFormikContext() as child of a component.\") : invariant(false) : void 0;\n return formik;\n}\n\nfunction formikReducer(state, msg) {\n switch (msg.type) {\n case 'SET_VALUES':\n return _extends({}, state, {\n values: msg.payload\n });\n\n case 'SET_TOUCHED':\n return _extends({}, state, {\n touched: msg.payload\n });\n\n case 'SET_ERRORS':\n if (isEqual(state.errors, msg.payload)) {\n return state;\n }\n\n return _extends({}, state, {\n errors: msg.payload\n });\n\n case 'SET_STATUS':\n return _extends({}, state, {\n status: msg.payload\n });\n\n case 'SET_ISSUBMITTING':\n return _extends({}, state, {\n isSubmitting: msg.payload\n });\n\n case 'SET_ISVALIDATING':\n return _extends({}, state, {\n isValidating: msg.payload\n });\n\n case 'SET_FIELD_VALUE':\n return _extends({}, state, {\n values: setIn(state.values, msg.payload.field, msg.payload.value)\n });\n\n case 'SET_FIELD_TOUCHED':\n return _extends({}, state, {\n touched: setIn(state.touched, msg.payload.field, msg.payload.value)\n });\n\n case 'SET_FIELD_ERROR':\n return _extends({}, state, {\n errors: setIn(state.errors, msg.payload.field, msg.payload.value)\n });\n\n case 'RESET_FORM':\n return _extends({}, state, msg.payload);\n\n case 'SET_FORMIK_STATE':\n return msg.payload(state);\n\n case 'SUBMIT_ATTEMPT':\n return _extends({}, state, {\n touched: setNestedObjectValues(state.values, true),\n isSubmitting: true,\n submitCount: state.submitCount + 1\n });\n\n case 'SUBMIT_FAILURE':\n return _extends({}, state, {\n isSubmitting: false\n });\n\n case 'SUBMIT_SUCCESS':\n return _extends({}, state, {\n isSubmitting: false\n });\n\n default:\n return state;\n }\n} // Initial empty states // objects\n\n\nvar emptyErrors = {};\nvar emptyTouched = {};\n\nfunction useFormik(_ref) {\n var _ref$validateOnChange = _ref.validateOnChange,\n validateOnChange = _ref$validateOnChange === void 0 ? true : _ref$validateOnChange,\n _ref$validateOnBlur = _ref.validateOnBlur,\n validateOnBlur = _ref$validateOnBlur === void 0 ? true : _ref$validateOnBlur,\n _ref$validateOnMount = _ref.validateOnMount,\n validateOnMount = _ref$validateOnMount === void 0 ? false : _ref$validateOnMount,\n isInitialValid = _ref.isInitialValid,\n _ref$enableReinitiali = _ref.enableReinitialize,\n enableReinitialize = _ref$enableReinitiali === void 0 ? false : _ref$enableReinitiali,\n onSubmit = _ref.onSubmit,\n rest = _objectWithoutPropertiesLoose(_ref, [\"validateOnChange\", \"validateOnBlur\", \"validateOnMount\", \"isInitialValid\", \"enableReinitialize\", \"onSubmit\"]);\n\n var props = _extends({\n validateOnChange: validateOnChange,\n validateOnBlur: validateOnBlur,\n validateOnMount: validateOnMount,\n onSubmit: onSubmit\n }, rest);\n\n var initialValues = useRef(props.initialValues);\n var initialErrors = useRef(props.initialErrors || emptyErrors);\n var initialTouched = useRef(props.initialTouched || emptyTouched);\n var initialStatus = useRef(props.initialStatus);\n var isMounted = useRef(false);\n var fieldRegistry = useRef({});\n\n if (process.env.NODE_ENV !== \"production\") {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useEffect(function () {\n !(typeof isInitialValid === 'undefined') ? process.env.NODE_ENV !== \"production\" ? invariant(false, 'isInitialValid has been deprecated and will be removed in future versions of Formik. Please use initialErrors or validateOnMount instead.') : invariant(false) : void 0; // eslint-disable-next-line\n }, []);\n }\n\n useEffect(function () {\n isMounted.current = true;\n return function () {\n isMounted.current = false;\n };\n }, []);\n\n var _React$useReducer = useReducer(formikReducer, {\n values: props.initialValues,\n errors: props.initialErrors || emptyErrors,\n touched: props.initialTouched || emptyTouched,\n status: props.initialStatus,\n isSubmitting: false,\n isValidating: false,\n submitCount: 0\n }),\n state = _React$useReducer[0],\n dispatch = _React$useReducer[1];\n\n var runValidateHandler = useCallback(function (values, field) {\n return new Promise(function (resolve, reject) {\n var maybePromisedErrors = props.validate(values, field);\n\n if (maybePromisedErrors == null) {\n // use loose null check here on purpose\n resolve(emptyErrors);\n } else if (isPromise(maybePromisedErrors)) {\n maybePromisedErrors.then(function (errors) {\n resolve(errors || emptyErrors);\n }, function (actualException) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\"Warning: An unhandled error was caught during validation in \", actualException);\n }\n\n reject(actualException);\n });\n } else {\n resolve(maybePromisedErrors);\n }\n });\n }, [props.validate]);\n /**\r\n * Run validation against a Yup schema and optionally run a function if successful\r\n */\n\n var runValidationSchema = useCallback(function (values, field) {\n var validationSchema = props.validationSchema;\n var schema = isFunction(validationSchema) ? validationSchema(field) : validationSchema;\n var promise = field && schema.validateAt ? schema.validateAt(field, values) : validateYupSchema(values, schema);\n return new Promise(function (resolve, reject) {\n promise.then(function () {\n resolve(emptyErrors);\n }, function (err) {\n // Yup will throw a validation error if validation fails. We catch those and\n // resolve them into Formik errors. We can sniff if something is a Yup error\n // by checking error.name.\n // @see https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string\n if (err.name === 'ValidationError') {\n resolve(yupToFormErrors(err));\n } else {\n // We throw any other errors\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\"Warning: An unhandled error was caught during validation in \", err);\n }\n\n reject(err);\n }\n });\n });\n }, [props.validationSchema]);\n var runSingleFieldLevelValidation = useCallback(function (field, value) {\n return new Promise(function (resolve) {\n return resolve(fieldRegistry.current[field].validate(value));\n });\n }, []);\n var runFieldLevelValidations = useCallback(function (values) {\n var fieldKeysWithValidation = Object.keys(fieldRegistry.current).filter(function (f) {\n return isFunction(fieldRegistry.current[f].validate);\n }); // Construct an array with all of the field validation functions\n\n var fieldValidations = fieldKeysWithValidation.length > 0 ? fieldKeysWithValidation.map(function (f) {\n return runSingleFieldLevelValidation(f, getIn(values, f));\n }) : [Promise.resolve('DO_NOT_DELETE_YOU_WILL_BE_FIRED')]; // use special case ;)\n\n return Promise.all(fieldValidations).then(function (fieldErrorsList) {\n return fieldErrorsList.reduce(function (prev, curr, index) {\n if (curr === 'DO_NOT_DELETE_YOU_WILL_BE_FIRED') {\n return prev;\n }\n\n if (curr) {\n prev = setIn(prev, fieldKeysWithValidation[index], curr);\n }\n\n return prev;\n }, {});\n });\n }, [runSingleFieldLevelValidation]); // Run all validations and return the result\n\n var runAllValidations = useCallback(function (values) {\n return Promise.all([runFieldLevelValidations(values), props.validationSchema ? runValidationSchema(values) : {}, props.validate ? runValidateHandler(values) : {}]).then(function (_ref2) {\n var fieldErrors = _ref2[0],\n schemaErrors = _ref2[1],\n validateErrors = _ref2[2];\n var combinedErrors = deepmerge.all([fieldErrors, schemaErrors, validateErrors], {\n arrayMerge: arrayMerge\n });\n return combinedErrors;\n });\n }, [props.validate, props.validationSchema, runFieldLevelValidations, runValidateHandler, runValidationSchema]); // Run all validations methods and update state accordingly\n\n var validateFormWithHighPriority = useEventCallback(function (values) {\n if (values === void 0) {\n values = state.values;\n }\n\n dispatch({\n type: 'SET_ISVALIDATING',\n payload: true\n });\n return runAllValidations(values).then(function (combinedErrors) {\n if (!!isMounted.current) {\n dispatch({\n type: 'SET_ISVALIDATING',\n payload: false\n });\n dispatch({\n type: 'SET_ERRORS',\n payload: combinedErrors\n });\n }\n\n return combinedErrors;\n });\n });\n useEffect(function () {\n if (validateOnMount && isMounted.current === true && isEqual(initialValues.current, props.initialValues)) {\n validateFormWithHighPriority(initialValues.current);\n }\n }, [validateOnMount, validateFormWithHighPriority]);\n var resetForm = useCallback(function (nextState) {\n var values = nextState && nextState.values ? nextState.values : initialValues.current;\n var errors = nextState && nextState.errors ? nextState.errors : initialErrors.current ? initialErrors.current : props.initialErrors || {};\n var touched = nextState && nextState.touched ? nextState.touched : initialTouched.current ? initialTouched.current : props.initialTouched || {};\n var status = nextState && nextState.status ? nextState.status : initialStatus.current ? initialStatus.current : props.initialStatus;\n initialValues.current = values;\n initialErrors.current = errors;\n initialTouched.current = touched;\n initialStatus.current = status;\n\n var dispatchFn = function dispatchFn() {\n dispatch({\n type: 'RESET_FORM',\n payload: {\n isSubmitting: !!nextState && !!nextState.isSubmitting,\n errors: errors,\n touched: touched,\n status: status,\n values: values,\n isValidating: !!nextState && !!nextState.isValidating,\n submitCount: !!nextState && !!nextState.submitCount && typeof nextState.submitCount === 'number' ? nextState.submitCount : 0\n }\n });\n };\n\n if (props.onReset) {\n var maybePromisedOnReset = props.onReset(state.values, imperativeMethods);\n\n if (isPromise(maybePromisedOnReset)) {\n maybePromisedOnReset.then(dispatchFn);\n } else {\n dispatchFn();\n }\n } else {\n dispatchFn();\n }\n }, [props.initialErrors, props.initialStatus, props.initialTouched]);\n useEffect(function () {\n if (isMounted.current === true && !isEqual(initialValues.current, props.initialValues)) {\n if (enableReinitialize) {\n initialValues.current = props.initialValues;\n resetForm();\n }\n\n if (validateOnMount) {\n validateFormWithHighPriority(initialValues.current);\n }\n }\n }, [enableReinitialize, props.initialValues, resetForm, validateOnMount, validateFormWithHighPriority]);\n useEffect(function () {\n if (enableReinitialize && isMounted.current === true && !isEqual(initialErrors.current, props.initialErrors)) {\n initialErrors.current = props.initialErrors || emptyErrors;\n dispatch({\n type: 'SET_ERRORS',\n payload: props.initialErrors || emptyErrors\n });\n }\n }, [enableReinitialize, props.initialErrors]);\n useEffect(function () {\n if (enableReinitialize && isMounted.current === true && !isEqual(initialTouched.current, props.initialTouched)) {\n initialTouched.current = props.initialTouched || emptyTouched;\n dispatch({\n type: 'SET_TOUCHED',\n payload: props.initialTouched || emptyTouched\n });\n }\n }, [enableReinitialize, props.initialTouched]);\n useEffect(function () {\n if (enableReinitialize && isMounted.current === true && !isEqual(initialStatus.current, props.initialStatus)) {\n initialStatus.current = props.initialStatus;\n dispatch({\n type: 'SET_STATUS',\n payload: props.initialStatus\n });\n }\n }, [enableReinitialize, props.initialStatus, props.initialTouched]);\n var validateField = useEventCallback(function (name) {\n // This will efficiently validate a single field by avoiding state\n // changes if the validation function is synchronous. It's different from\n // what is called when using validateForm.\n if (fieldRegistry.current[name] && isFunction(fieldRegistry.current[name].validate)) {\n var value = getIn(state.values, name);\n var maybePromise = fieldRegistry.current[name].validate(value);\n\n if (isPromise(maybePromise)) {\n // Only flip isValidating if the function is async.\n dispatch({\n type: 'SET_ISVALIDATING',\n payload: true\n });\n return maybePromise.then(function (x) {\n return x;\n }).then(function (error) {\n dispatch({\n type: 'SET_FIELD_ERROR',\n payload: {\n field: name,\n value: error\n }\n });\n dispatch({\n type: 'SET_ISVALIDATING',\n payload: false\n });\n });\n } else {\n dispatch({\n type: 'SET_FIELD_ERROR',\n payload: {\n field: name,\n value: maybePromise\n }\n });\n return Promise.resolve(maybePromise);\n }\n } else if (props.validationSchema) {\n dispatch({\n type: 'SET_ISVALIDATING',\n payload: true\n });\n return runValidationSchema(state.values, name).then(function (x) {\n return x;\n }).then(function (error) {\n dispatch({\n type: 'SET_FIELD_ERROR',\n payload: {\n field: name,\n value: error[name]\n }\n });\n dispatch({\n type: 'SET_ISVALIDATING',\n payload: false\n });\n });\n }\n\n return Promise.resolve();\n });\n var registerField = useCallback(function (name, _ref3) {\n var validate = _ref3.validate;\n fieldRegistry.current[name] = {\n validate: validate\n };\n }, []);\n var unregisterField = useCallback(function (name) {\n delete fieldRegistry.current[name];\n }, []);\n var setTouched = useEventCallback(function (touched, shouldValidate) {\n dispatch({\n type: 'SET_TOUCHED',\n payload: touched\n });\n var willValidate = shouldValidate === undefined ? validateOnBlur : shouldValidate;\n return willValidate ? validateFormWithHighPriority(state.values) : Promise.resolve();\n });\n var setErrors = useCallback(function (errors) {\n dispatch({\n type: 'SET_ERRORS',\n payload: errors\n });\n }, []);\n var setValues = useEventCallback(function (values, shouldValidate) {\n var resolvedValues = isFunction(values) ? values(state.values) : values;\n dispatch({\n type: 'SET_VALUES',\n payload: resolvedValues\n });\n var willValidate = shouldValidate === undefined ? validateOnChange : shouldValidate;\n return willValidate ? validateFormWithHighPriority(resolvedValues) : Promise.resolve();\n });\n var setFieldError = useCallback(function (field, value) {\n dispatch({\n type: 'SET_FIELD_ERROR',\n payload: {\n field: field,\n value: value\n }\n });\n }, []);\n var setFieldValue = useEventCallback(function (field, value, shouldValidate) {\n dispatch({\n type: 'SET_FIELD_VALUE',\n payload: {\n field: field,\n value: value\n }\n });\n var willValidate = shouldValidate === undefined ? validateOnChange : shouldValidate;\n return willValidate ? validateFormWithHighPriority(setIn(state.values, field, value)) : Promise.resolve();\n });\n var executeChange = useCallback(function (eventOrTextValue, maybePath) {\n // By default, assume that the first argument is a string. This allows us to use\n // handleChange with React Native and React Native Web's onChangeText prop which\n // provides just the value of the input.\n var field = maybePath;\n var val = eventOrTextValue;\n var parsed; // If the first argument is not a string though, it has to be a synthetic React Event (or a fake one),\n // so we handle like we would a normal HTML change event.\n\n if (!isString(eventOrTextValue)) {\n // If we can, persist the event\n // @see https://reactjs.org/docs/events.html#event-pooling\n if (eventOrTextValue.persist) {\n eventOrTextValue.persist();\n }\n\n var target = eventOrTextValue.target ? eventOrTextValue.target : eventOrTextValue.currentTarget;\n var type = target.type,\n name = target.name,\n id = target.id,\n value = target.value,\n checked = target.checked,\n outerHTML = target.outerHTML,\n options = target.options,\n multiple = target.multiple;\n field = maybePath ? maybePath : name ? name : id;\n\n if (!field && process.env.NODE_ENV !== \"production\") {\n warnAboutMissingIdentifier({\n htmlContent: outerHTML,\n documentationAnchorLink: 'handlechange-e-reactchangeeventany--void',\n handlerName: 'handleChange'\n });\n }\n\n val = /number|range/.test(type) ? (parsed = parseFloat(value), isNaN(parsed) ? '' : parsed) : /checkbox/.test(type) // checkboxes\n ? getValueForCheckbox(getIn(state.values, field), checked, value) : options && multiple // \n ? getSelectedValues(options)\n : value;\n }\n\n if (field) {\n // Set form fields by name\n setFieldValue(field, val);\n }\n },\n [setFieldValue, state.values]\n );\n\n const handleChange = useEventCallback(\n (\n eventOrPath: string | React.ChangeEvent\n ): void | ((eventOrTextValue: string | React.ChangeEvent) => void) => {\n if (isString(eventOrPath)) {\n return event => executeChange(event, eventOrPath);\n } else {\n executeChange(eventOrPath);\n }\n }\n );\n\n const setFieldTouched = useEventCallback(\n (field: string, touched: boolean = true, shouldValidate?: boolean) => {\n dispatch({\n type: 'SET_FIELD_TOUCHED',\n payload: {\n field,\n value: touched,\n },\n });\n const willValidate =\n shouldValidate === undefined ? validateOnBlur : shouldValidate;\n return willValidate\n ? validateFormWithHighPriority(state.values)\n : Promise.resolve();\n }\n );\n\n const executeBlur = React.useCallback(\n (e: any, path?: string) => {\n if (e.persist) {\n e.persist();\n }\n const { name, id, outerHTML } = e.target;\n const field = path ? path : name ? name : id;\n\n if (!field && __DEV__) {\n warnAboutMissingIdentifier({\n htmlContent: outerHTML,\n documentationAnchorLink: 'handleblur-e-any--void',\n handlerName: 'handleBlur',\n });\n }\n\n setFieldTouched(field, true);\n },\n [setFieldTouched]\n );\n\n const handleBlur = useEventCallback(\n (eventOrString: any): void | ((e: any) => void) => {\n if (isString(eventOrString)) {\n return event => executeBlur(event, eventOrString);\n } else {\n executeBlur(eventOrString);\n }\n }\n );\n\n const setFormikState = React.useCallback(\n (\n stateOrCb:\n | FormikState\n | ((state: FormikState) => FormikState)\n ): void => {\n if (isFunction(stateOrCb)) {\n dispatch({ type: 'SET_FORMIK_STATE', payload: stateOrCb });\n } else {\n dispatch({ type: 'SET_FORMIK_STATE', payload: () => stateOrCb });\n }\n },\n []\n );\n\n const setStatus = React.useCallback((status: any) => {\n dispatch({ type: 'SET_STATUS', payload: status });\n }, []);\n\n const setSubmitting = React.useCallback((isSubmitting: boolean) => {\n dispatch({ type: 'SET_ISSUBMITTING', payload: isSubmitting });\n }, []);\n\n const submitForm = useEventCallback(() => {\n dispatch({ type: 'SUBMIT_ATTEMPT' });\n return validateFormWithHighPriority().then(\n (combinedErrors: FormikErrors) => {\n // In case an error was thrown and passed to the resolved Promise,\n // `combinedErrors` can be an instance of an Error. We need to check\n // that and abort the submit.\n // If we don't do that, calling `Object.keys(new Error())` yields an\n // empty array, which causes the validation to pass and the form\n // to be submitted.\n\n const isInstanceOfError = combinedErrors instanceof Error;\n const isActuallyValid =\n !isInstanceOfError && Object.keys(combinedErrors).length === 0;\n if (isActuallyValid) {\n // Proceed with submit...\n //\n // To respect sync submit fns, we can't simply wrap executeSubmit in a promise and\n // _always_ dispatch SUBMIT_SUCCESS because isSubmitting would then always be false.\n // This would be fine in simple cases, but make it impossible to disable submit\n // buttons where people use callbacks or promises as side effects (which is basically\n // all of v1 Formik code). Instead, recall that we are inside of a promise chain already,\n // so we can try/catch executeSubmit(), if it returns undefined, then just bail.\n // If there are errors, throw em. Otherwise, wrap executeSubmit in a promise and handle\n // cleanup of isSubmitting on behalf of the consumer.\n let promiseOrUndefined;\n try {\n promiseOrUndefined = executeSubmit();\n // Bail if it's sync, consumer is responsible for cleaning up\n // via setSubmitting(false)\n if (promiseOrUndefined === undefined) {\n return;\n }\n } catch (error) {\n throw error;\n }\n\n return Promise.resolve(promiseOrUndefined)\n .then(result => {\n if (!!isMounted.current) {\n dispatch({ type: 'SUBMIT_SUCCESS' });\n }\n return result;\n })\n .catch(_errors => {\n if (!!isMounted.current) {\n dispatch({ type: 'SUBMIT_FAILURE' });\n // This is a legit error rejected by the onSubmit fn\n // so we don't want to break the promise chain\n throw _errors;\n }\n });\n } else if (!!isMounted.current) {\n // ^^^ Make sure Formik is still mounted before updating state\n dispatch({ type: 'SUBMIT_FAILURE' });\n // throw combinedErrors;\n if (isInstanceOfError) {\n throw combinedErrors;\n }\n }\n return;\n }\n );\n });\n\n const handleSubmit = useEventCallback(\n (e?: React.FormEvent) => {\n if (e && e.preventDefault && isFunction(e.preventDefault)) {\n e.preventDefault();\n }\n\n if (e && e.stopPropagation && isFunction(e.stopPropagation)) {\n e.stopPropagation();\n }\n\n // Warn if form submission is triggered by a