some properties of initialState are not accessible
shaogatalam opened this issue · 2 comments
shaogatalam commented
At index.js file all the properties of initialState are available,
:: index.js ::
console.log(store.getState().Profile_personal_data.personal_data); // [showing proper value]
console.log(store.getState().Profile_personal_data.demo); // [showing proper value]
console.log(store.getState().Profile_personal_data.status); // [showing proper value]
console.log(store.getState().Profile_personal_data.account_type); // [showing proper value]
ReactDOM.render(
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<App />
</PersistGate>
</Provider>,
document.getElementById("root")
);
When I try to access the value of "demo", "personal_data", in a react component I get undefined,
::::: React component => PersonalDataComponent.js
import React, { useEffect } from "react";
import { useSelector, useDispatch } from "react-redux";
import { personaldata_ } from "../../features/profile/PersonalData";
function PersonalData() {
var rolePower = useSelector((state) => state.dashTops.rolePower);
var personal_data = useSelector((state) => state.Profile_personal_data.personal_data);
var demo_value = useSelector((state) => state.Profile_personal_data.demo);
console.log(demo_value); // => undefined[showing undefined]
}
::::: Slice configuration => PersonalDataSlice.js
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
import axios from "axios";
var initialState = {
personal_data: {},
demo: 0,
status: null,
account_type: {}
};
export const Profile_personal_data_Slice = createSlice({
name: "Profile_personal_data",
initialState,
reducers: {
demo: (state, action) => {
state.demo = 1;
},
},
});
export const { demo } = Profile_personal_data_Slice.actions;
phryneas commented
I would assume you have conflicting state persisted and now it's restoring that?
timdorr commented
Yes, it looks to be that. You have bad state stored from a prior run of this app.
Regardless, the issue tracker here on GitHub is reserved for bug reports and feature requests. For usage questions (which is what I believe this is), please use our Discussions page, Stack Overflow, or Reactiflux where there are a lot more people ready to help you out. Thanks!