I am using the useSelector code snippet below:
const user = useSelector<RootStateOrAny, typeof typeRootReducer>((state) => state.user)
This is how it looks in the rootReducer:
const rootReducer = combineReducers({
user: userReducer
})
export default rootReducer
export type typeRootReducer = ReturnType<typeof rootReducer>
Initial State:
const initState = {
user: null
}
Whenever I try to access console.log(user.user.name)
, I get an error message saying
cannot read property name of null