🐛 Bug Report
I am trying to add immer to a react native expo app with redux.
I am getting this error:
React Native - Immer with Expo.io Reducer “user” returned undefined during initialization
To Reproduce
Before Immer (working)
import { LOGIN_ACTION } from '../actions/actionTypes';
const initialState = {
user: false,
};
const User = (state = initialState, action) => {
switch (action.type) {
case LOGIN_ACTION:
return {
...state,
'user': action.user
};
default:
return state;
}
};
export default User;
After Immer (not working)
import produce from 'immer';
import { LOGIN_ACTION } from '../actions/actionTypes';
const initialState = {
user: false,
};
const User = (state = initialState, action) => {
produce((state, draft) => {
switch (action.type) {
case LOGIN_ACTION:
draft.user = action.user;
break;
}
});
};
export default User;
What am I doing wrong?
Here is the full error I am getting:
Reducer "user" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined. If you don't want to set a value for this reducer, you can use null instead of undefined.
redux.js:366:22 forEach [native code]:0 assertReducerShape redux.js:359:32 combineReducers redux.js:422:23 index.js:4:31 loadModuleImplementation require.js:292:12 index.js:2 loadModuleImplementation require.js:292:12 App.js:5 loadModuleImplementation require.js:292:12 AppEntry.js:2 loadModuleImplementation require.js:292:12 guardedLoadModule require.js:179:45 global code :0
Expected behavior
Should work like react! I followed this example:
https://github.com/react-boilerplate/react-boilerplate/blob/master/app/containers/HomePage/reducer.js
🐛 Bug Report
I am trying to add immer to a react native expo app with redux.
I am getting this error:
React Native - Immer with Expo.io Reducer “user” returned undefined during initialization
To Reproduce
Before Immer (working)
After Immer (not working)
What am I doing wrong?
Here is the full error I am getting:
Expected behavior
Should work like react! I followed this example:
https://github.com/react-boilerplate/react-boilerplate/blob/master/app/containers/HomePage/reducer.js