Home > Software engineering >  would redux trigger re render if a nested property is updated?
would redux trigger re render if a nested property is updated?

Time:07-13


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?

CodePudding user response:

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)

  • Related