I am running the ABP React Mobile code from https://abp.io/ and am receiving an unhandled promise exception when logging in to the mobile application.
Steps to replicate from scratch:
- Create an ABP project
- Migrate the DB
- Log in to web app
- Create user and log in to test if DB will update
- Set up Conveyor to get IP address for react front end
- Ran Yarn to init react project
- Opened react project and added IP and port from Conveyor to Environment.js
- Ran Yarn start
- Open Expo on iOS and open project
- Log in with Admin and User credentials
Note: I do not think that the key should be undefined, so checking if the value is undefined will not solve the problem, only confirm that the key is undefined and we already know this from the error.
Results in this error:
[Unhandled promise rejection: TypeError: undefined is not an object (evaluating 'delete state.activeLoadings[action.payload.key]')]
* src\store\reducers\LoadingReducer.js:10:6 in builder.addCase$argument_1
* http://10.0.0.192:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:211765:15 in <unknown>
* [native code]:null in <unknown>
* [native code]:null in reduce
- node_modules\redux\lib\redux.js:463:34 in combination
* http://10.0.0.192:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:228985:32 in <unknown>
- node_modules\redux\lib\redux.js:217:8 in dispatch
- node_modules\@redux-saga\core\dist\redux-saga-core.dev.cjs.js:1412:9 in <anonymous>
* src\screens\Login\LoginScreen.js:52:8 in login.then.then$argument_0
- node_modules\react-native\node_modules\promise\setimmediate\finally.js:12:28 in then$argument_1
- node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 in tryCallOne
- node_modules\react-native\node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14 in _callTimer
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:181:14 in _callImmediatesPass
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:441:30 in callImmediates- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:387:6 in __callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:135:6 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:134:4 in flushedQueue
* [native code]:null in flushedQueue
* [native code]:null in callFunctionReturnFlushedQueue
Code related to error:
import { createReducer } from '@reduxjs/toolkit';
import LoadingActions from '../actions/LoadingActions';
const initialState = { activeLoadings: {}, loading: false };
export default createReducer(initialState, builder =>
builder
.addCase(LoadingActions.start, (state, action) => {
const { key, opacity } = action.payload;
return {
...state,
actives: { ...state.activeLoadings, [key]: action },
loading: true,
opacity,
};
})
.addCase(LoadingActions.stop, (state, action) => {
delete state.activeLoadings[action.payload.key];
state.loading = !!Object.keys(state.activeLoadings).length;
})
.addCase(LoadingActions.clear, () => ({})),
);