react-better-html 1.1.63 → 1.1.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/utils/hooks.d.ts +1 -0
- package/dist/utils/hooks.js +5 -0
- package/package.json +1 -1
package/dist/utils/hooks.d.ts
CHANGED
|
@@ -76,6 +76,7 @@ export declare function useForm<FormFields extends Record<string | number, strin
|
|
|
76
76
|
reset: () => void;
|
|
77
77
|
requiredFields: (keyof FormFields)[] | undefined;
|
|
78
78
|
isDirty: boolean;
|
|
79
|
+
isValid: boolean;
|
|
79
80
|
};
|
|
80
81
|
export declare function useUrlQuery(): {
|
|
81
82
|
setQuery: (query: Record<string, string | number>, keepHistory?: boolean) => void;
|
package/dist/utils/hooks.js
CHANGED
|
@@ -379,6 +379,10 @@ function useForm(options) {
|
|
|
379
379
|
setErrors({});
|
|
380
380
|
}, [defaultValues]);
|
|
381
381
|
const isDirty = (0, react_1.useMemo)(() => Object.keys(defaultValues).some((key) => defaultValues[key] !== values[key]), [defaultValues, values]);
|
|
382
|
+
const isValid = (0, react_1.useMemo)(() => {
|
|
383
|
+
const validationErrors = validate?.(values) || {};
|
|
384
|
+
return Object.keys(validationErrors).length === 0;
|
|
385
|
+
}, [validate, values]);
|
|
382
386
|
return {
|
|
383
387
|
values,
|
|
384
388
|
errors,
|
|
@@ -396,6 +400,7 @@ function useForm(options) {
|
|
|
396
400
|
reset,
|
|
397
401
|
requiredFields,
|
|
398
402
|
isDirty,
|
|
403
|
+
isValid,
|
|
399
404
|
};
|
|
400
405
|
}
|
|
401
406
|
function useUrlQuery() {
|