import type { FormikProps } from 'formik'; /** * Sometimes a form allows the user to choose between multiple mutually exclusive sets of fields. * This hook saves and restores mutually exclusive fields when the user interactively toggles between them. * * For example, an order form may have separate fields for ordering a pizza or a sandwich. When the user selects * "pizza", this hook saves a copy of the user's currently entered "sandwich" data and then clears the "sandwich" fields. * If the user then switches back to "sandwich", the hook restores the "sandwich" data and saves/clears the "pizza" fields. * * Note: this hook does not explicitly attempt to manage default values for form fields * * @param formik * @param currentFieldSetKey the key for the current field (the form mode, e.g., the value of the selected radio button) * @param mutuallyExclusiveFieldSets an object with: * - keys: one for each mutually exclusive fieldset * - values: lodash paths to the form fields exclusively owned by that fieldset * * Example: * * // Restores previous "pizza" form data ('toppings', 'crust', 'sauce') when the form mode switches back to 'pizza' * // Restores previous "sandwich" form data ('bread', 'meat', 'cheese') when the form mode switches back to 'sandwich' * * useSaveRestoreMutuallyExclusiveFields(formik, pizzaOrSandwich, { * { pizza: ["toppings", "crust", "sauce" ] }, * { sandwich: ["bread", "meat", "cheese" ] }, * }); * * } /> * * { formik.values.pizzaOrSandwich === 'pizza' && (<> * } /> * } /> * } /> * } /> * )} * * { formik.values.pizzaOrSandwich === 'sandwich' && (<> * } /> * } /> * } /> * )} */ export declare function useSaveRestoreMutuallyExclusiveFields(formik: FormikProps, currentFieldSetKey: string, mutuallyExclusiveFieldSets: { [fieldSetKey: string]: string[]; }): void;