The code is compiled by webpack but I have an error on the browser console.
The problem seems to be at the line : 'switch (action.type)'
Here is the code :
./reducer
import { produce } from 'immer';
import ActionTypeKeys from './actionTypeKeys';
import { AuthAction } from './actionTypes';
export type AuthState = {
isLoggedIn: boolean;
};
const initialState = { isLoggedIn: false };
export const authReducer = produce(
(action: AuthAction, draft: AuthState = initialState) => {
switch (action.type) {
case ActionTypeKeys.IS_LOGIN:
draft.isLoggedIn = action.payload;
break;
default:
throw new Error('No matching ActionTypeKeys was found!');
}
return draft;
}
);
./actionTypeKeys
enum ActionTypeKeys {
REFRESH_TOKEN = 'auth/REFRESH_TOKEN',
IS_LOGIN = 'auth/IS_LOGIN',
}
export default ActionTypeKeys;
The console error :
reducer.ts:14 Uncaught TypeError: Cannot read properties of undefined (reading 'type')
at reducer.ts:14:18
at immer.esm.js:1:16007
at e.produce (immer.esm.js:1:16373)
at immer.esm.js:1:15969
at redux.js:436:1
at Array.forEach (<anonymous>)
at assertReducerShape (redux.js:434:1)
at combineReducers (redux.js:499:1)
at Module../src/store/rootReducer.ts (rootReducer.ts:11:43)
at __webpack_require__ (bootstrap:24:1)
The error is triggering the line 'switch (action.type)'
I have no idea how to solve it.
Can someone bring me the light ?