I am fetching data (an object) into a redux state and showing into textarea when user clicks on edit:
const regionData = useSelector((state) => state.myReducer.userDetailList.region);
but first time it gives me below error:
Uncaught TypeError: Cannot read properties of undefined (reading 'region')
also this error occurred when i changed code as per eslint suggestion:
i.e.
Use an object spread instead of `Object.assign` eg: `{ ...foo }`
Old Code:
return Object.assign({}, state, {
userDetailList: {
region: action.userDetailsPayload.region,
},
});
New Code:
const userDetailList = {
region: action.userDetailsPayload.region,
};
return { ...state, ...userDetailList };
As a result userDetailList showing as BLANK in Chrome redux-devtool. its working with old code (Object.assign)
I am new to react and redux, so any help is much appreciated. Thanks!
I had a promblem same this one. Finally I've found out that if I use term "Reducer" or "State" at the end of state's name or reducer's name that are witten by me, my code runs with error
Uncaught TypeError: Cannot read properties of undefined (reading 'result_201')
my reducer:
and my index.tsx file for defining CobineReducer and RoutState:
it runs with that error when I want acceess to the state in another file:
but if I remove "State" and "Reducer" term and change my index.tsx file to :
it works now ! :)