"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useFormikHelpers = void 0;
const tslib_1 = require("tslib");
const formik_1 = require("formik");
const React = tslib_1.__importStar(require("react"));
// workaround for https://github.com/jaredpalmer/formik/issues/2268
// formik helpers are new a instance on every formik store update :(
const useFormikHelpers = (fieldID) => {
    const [{ value }, , { setValue, setTouched }] = (0, formik_1.useField)(fieldID);
    const idsRef = React.useRef(value);
    idsRef.current = value;
    const setValueRef = React.useRef(setValue);
    setValueRef.current = setValue;
    const setTouchedRef = React.useRef(setTouched);
    setTouchedRef.current = setTouched;
    const setFieldValue = React.useCallback((value, shouldValidate) => {
        setValueRef.current(value, shouldValidate);
    }, []);
    const setFieldTouched = React.useCallback((touched, shouldValidate) => setTouchedRef.current(touched, shouldValidate), []);
    const valueRef = React.useRef(value);
    valueRef.current = value;
    return { setValue: setFieldValue, setTouched: setFieldTouched, valueRef };
};
exports.useFormikHelpers = useFormikHelpers;
//# sourceMappingURL=useFormikHelpers.js.map