Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

would redux trigger re render if a nested property is updated?


export const userSlice = createSlice({
  name: "user",
  initialState: {
    info: {
      dob: null,
    }
  }
})

What if the dob property is updated but the reference that info is pointing to is not changed? Would this cause a component which depends on user.info.dob to re render?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Depends on the data type.
If it is primitive – (number, string) yes

If its an object, then you have to reference (point to another object).
It can be as simple as {... prevObject, newProperties }

But deeply nested can make life miserable. So using a library called Immer is recommended (https://beta.reactjs.org/learn/choosing-the-state-structure)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading