-1

As soon as I use dispatch to change a property of the object in redux state, suddenly the whole component re-mounts in react native. Below is a part of my Slice.tsx:

const initialState = { LocalStorageInfoInitialState: { "IsLoggedIn": false, "IsFirstLaunch": true, "StatsEnabled": true, "Schedule_Walkthrough_Completed": false, "Statistics_Walkthrough_Completed": false } as LocalStorageInfoDataType, StudentInfoInitialState: {} as StudentInfoDataType, ScheduleArrayInitialState: [] as ScheduleArrayItem[], ExistingSubjectsArrayInitialState: [] as ExistingSubjectsArrayItem[], StudentsDataArrayInitialState:[] as StudentsDataArrayType[] } export const LocalStorageInfoSlice = createSlice({ name: 'LocalStorageInfo', initialState, reducers: { updateLocalStorageInfo: (state, action) = { if (action.payload == "Login") { state.LocalStorageInfoInitialState["IsLoggedIn"] = true } else if (action.payload == "Logout") { state.LocalStorageInfoInitialState["IsLoggedIn"] = false } else if (action.payload == "FirstLaunch") { state.LocalStorageInfoInitialState["IsFirstLaunch"] = false } else if (action.payload == "EnableStats") { state.LocalStorageInfoInitialState["StatsEnabled"] = true } else if (action.payload == "DisableStats") { state.LocalStorageInfoInitialState["StatsEnabled"] = false } else if (action.payload == "Schedule_Walkthrough_Completed") { state.LocalStorageInfoInitialState["Schedule_Walkthrough_Completed"] = true } else if (action.payload == "Statistics_Walkthrough_Completed") { state.LocalStorageInfoInitialState["Statistics_Walkthrough_Completed"] = true } } } }) 

Surprisingly, when I use dispatch to make changes in ScheduleArrayInitialState, ExistingSubjectsArrayInitialState and StudentsDataArrayInitialState which are an array as a whole in which I just push the value, everything works fine. But when I make changes in the objects of LocalStorageInfoInitialState and StudentInfoInitialState, it just re-mounts un-necessarily.

Please help me fix this problem. I am stuck with it for past 6 months with no solution.

New contributor
Archit Gupta is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
5
  • Can you please format your question better? You can wrap multiple lines of code within triple backticks and generally markdown works. this page has more help with formatting. Commented yesterday
  • Ok. Did it. I was not aware being new Commented yesterday
  • do you also have the component that this affects, and perhaps any parent that also uses this data? Commented yesterday
  • Yes, I can provide you exact link of the code from my github repo below. The problem is on the 371st line in Statistics.tsx file where I am using dispatch with a toggle button as a function : github.com/RAWLICK/Rescheduler-App/blob/main/src/Components/… Commented yesterday
  • What "dispatch" are you referring to? What is remounting? Please edit to include a relevant minimal reproducible example of the code that reproduces the issue you are asking for help fixing, and any debugging logs and details you have collected from any investigation. This will help readers better understand what you are asking. Commented yesterday

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.