Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

163
Vistas
useState does not updates when useSelector is updated

I think it is weird, but I do not understand why useState does not being set to new value. When looking at the picture we could see useSelector is updated and it should update useState aswell. I'm talking about flatData state. From what I understand flatData`` should get currentColivingdata at the first render. Then, whenevercurrentColivingis updated -flatData``` should be updated. However, the picture says different story. Here is the code:

function FlatInformation() {
  const currentColiving = useSelector(selectCurrentColiving);
  const [imageFiles, setImageFiles] = useState([]);
  const [flatData, setFlatData] = useState({
    name: currentColiving?.title || "",
    description: currentColiving?.description || "",
    photos: currentColiving?.imageUrl || [],
    amenities: currentColiving?.amenities || [],
  });
  // Boolean whether a person can edit coliving settings or not.
  const flatSettingsEditMode = useSelector(selectIsInSettingsEditMode);

  useEffect(() => {
    if (currentColiving) {
      console.log(flatData, 'flatData-begin');
      setFlatData((prevState) => ({
        name: currentColiving.title,
        description: currentColiving.description,
        photos: currentColiving.imageUrl,
        amenities: currentColiving.amenities,
      }));
      console.log(currentColiving);
      console.log(flatData, 'Flatdata-end');
    }
  }, [currentColiving]);

  useEffect(() => {
    console.log(flatData, "flatData");
  }, [flatData]);
return (
<div>ommited</div>)

}

Pictures: enter image description here

about 4 years ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda