use-form-auto-save
Version:
A customizable React hook for automatically saving and restoring form data with support for localStorage, sessionStorage, and external APIs.
16 lines • 853 B
JavaScript
export function validateConfig(config) {
const { formKey, storageType = 'localStorage', saveFunction, formData, control, } = config;
if (!formKey || typeof formKey !== 'string') {
throw new Error('[useFormAutoSave]: "formKey" is required and must be a non-empty string.');
}
if (!formData && !control) {
throw new Error('[useFormAutoSave]: Either "formData" or "control" must be provided.');
}
if (storageType === 'api' && typeof saveFunction !== 'function') {
throw new Error('[useFormAutoSave]: When "storageType" is "api", a valid "saveFunction" must be provided.');
}
if (storageType !== 'api' && saveFunction) {
console.warn('[useFormAutoSave]: "saveFunction" provided but storageType is not "api". "saveFunction" will be ignored.');
}
}
//# sourceMappingURL=validateConfig.js.map