diff --git a/src/components/Componentes/question-birthplace.tsx b/src/components/Componentes/question-birthplace.tsx index 6533db8..bc10c05 100644 --- a/src/components/Componentes/question-birthplace.tsx +++ b/src/components/Componentes/question-birthplace.tsx @@ -182,6 +182,8 @@ export function QuestionBirthplace({ return () => window.removeEventListener("keydown", handleKeyDown); }, [isOpen, closeSheet]); + const lastInternalAnswerRef = useRef(null); + const updateAnswers = (country: string, city: string) => { const cleanCountry = country?.trim() || ""; const cleanCity = city?.trim() || ""; @@ -189,6 +191,7 @@ export function QuestionBirthplace({ cleanCity && cleanCountry ? `${cleanCity}, ${cleanCountry}` : cleanCity || cleanCountry || null; + lastInternalAnswerRef.current = formatted; setAnswerValue(question, formatted); }; @@ -266,8 +269,11 @@ export function QuestionBirthplace({ updateAnswers(country, city); }; - // Synchronize state if rawValue changes externally + // Synchronize state ONLY if rawValue changes externally (e.g. draft fetch or reset) useEffect(() => { + if (rawValue === lastInternalAnswerRef.current) { + return; + } const updated = parseValue(rawValue); const resolvedC = resolveCountryName(updated.country, locale); if (resolvedC && resolvedC !== selectedCountry) {