Compare commits
2 Commits
81e59777cb
...
ab12f5815e
| Author | SHA1 | Date | |
|---|---|---|---|
| ab12f5815e | |||
| c99cab0e51 |
@ -1,5 +1,5 @@
|
|||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { useEffect } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
import { FieldValues, UseFormProps, UseFormReturn, useForm } from "react-hook-form";
|
import { FieldValues, UseFormProps, UseFormReturn, useForm } from "react-hook-form";
|
||||||
import * as z4 from "zod/v4/core";
|
import * as z4 from "zod/v4/core";
|
||||||
|
|
||||||
@ -28,20 +28,40 @@ export function useHookForm<TFields extends FieldValues = FieldValues, TContext
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
formState: { isDirty },
|
formState: { isDirty },
|
||||||
|
reset,
|
||||||
} = form;
|
} = form;
|
||||||
|
|
||||||
|
// Evita bucles de reset: guarda última instantánea aplicada
|
||||||
|
const lastAppliedRef = useRef<unknown>(undefined);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
onDirtyChange?.(isDirty);
|
onDirtyChange?.(isDirty);
|
||||||
}, [isDirty, onDirtyChange]);
|
}, [isDirty, onDirtyChange]);
|
||||||
|
|
||||||
useEffect(() => {
|
/*useEffect(() => {
|
||||||
const applyReset = async () => {
|
const applyReset = async () => {
|
||||||
const values = typeof initialValues === "function" ? await initialValues() : initialValues;
|
const values = typeof initialValues === "function" ? await initialValues() : initialValues;
|
||||||
|
|
||||||
form.reset(values);
|
form.reset(values);
|
||||||
};
|
};
|
||||||
applyReset();
|
applyReset();
|
||||||
}, [initialValues, form]);
|
}, [initialValues, form]);*/
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let mounted = true;
|
||||||
|
const apply = async () => {
|
||||||
|
const next = typeof initialValues === "function" ? await initialValues() : initialValues;
|
||||||
|
// Evita reset redundante
|
||||||
|
if (mounted && JSON.stringify(next) !== JSON.stringify(lastAppliedRef.current)) {
|
||||||
|
reset(next as TFields);
|
||||||
|
lastAppliedRef.current = next;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
void apply();
|
||||||
|
return () => {
|
||||||
|
mounted = false;
|
||||||
|
};
|
||||||
|
}, [initialValues, reset]);
|
||||||
|
|
||||||
return form;
|
return form;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -65,7 +65,7 @@
|
|||||||
--shadow-xl: 1px 1px 6px 0px hsl(0 0% 0% / 0.1), 1px 8px 10px -1px hsl(0 0% 0% / 0.1);
|
--shadow-xl: 1px 1px 6px 0px hsl(0 0% 0% / 0.1), 1px 8px 10px -1px hsl(0 0% 0% / 0.1);
|
||||||
--shadow-2xl: 1px 1px 6px 0px hsl(0 0% 0% / 0.25);
|
--shadow-2xl: 1px 1px 6px 0px hsl(0 0% 0% / 0.25);
|
||||||
--tracking-normal: 0rem;
|
--tracking-normal: 0rem;
|
||||||
--spacing: 0.25rem;
|
--spacing: 0.20rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dark {
|
.dark {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user