Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!