1

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?

1 Answers1

2

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)

user18821127
  • 318
  • 1
  • 8