Browse Source

fix: persist city in initial state

mantendo a cidade selecionada e só deixando vazio caso mude de estado
newFeature
bobmw 8 months ago
parent
commit
3a2e30bf2d
  1. 12
      src/app/screens/UpdateUserInfoScreen.js

12
src/app/screens/UpdateUserInfoScreen.js

@ -89,12 +89,20 @@ function MaterialCommunityIconsCustom({
function CityPicker({ name }) { function CityPicker({ name }) {
const [items, setItems] = useState([]); const [items, setItems] = useState([]);
const [isInitialRender, setIsInitialRender] = useState(true);
const { values, setValues } = useFormikContext(); const { values, setValues } = useFormikContext();
const state = values["state"]; const state = values["state"];
useEffect(() => { useEffect(() => {
state && setItems(statesToCities[state].cities);
setValues({ ...values, city: "" });
if (isInitialRender) {
state && setItems(statesToCities[state].cities);
setIsInitialRender(false);
} else {
state && setItems(statesToCities[state].cities);
setValues({ ...values, city: "" });
}
}, [state]); }, [state]);
return ( return (

Loading…
Cancel
Save