Having trouble migrating from react-navigation v1 to v3.11 - reactjs

I'm trying to migrate our codebase to use react-navigation: 3.11 from v1 and having issues. I created a small gist here to run through the issue and provided codebase.
I am using react-navigation-redux-helpers with the new react-navigation to use the createReduxContainer function in other to maintain my previous redux setup.
I'm getting this error - Cannot read property 'routes' of undefined
https://gist.github.com/bwoodlt/773c62d4ba3dbe0cea150a9d956bec3f
// #flow
// root navigator
import React from 'react';
import { Platform } from 'react-native';
import { createStackNavigator, createAppContainer } from 'react-navigation';
import TabNavigation from './TabNavigation';
import FCLaunch from '../../Components/FCLaunch';
import { FCLAUNCH } from '../constants';
import { HeaderText } from '../Components';
import * as actionsOnboarding from '../../Screens/Onboarding/actions';
import StagingArea from '../StagingArea';
const RouteConfigs = {
StagingArea: {
screen: StagingArea,
defaultNavigationOptions: {
header: null
}
},
[FCLAUNCH]: {
screen: FCLaunch,
navigationOption: () => ({
header: null
})
}
};
const StackNavigatorConfig = {
initialRouteName: 'StagingArea',
mode: Platform.OS === 'ios' ? 'modal' : 'card'
};
export default createAppContainer(
createStackNavigator(RouteConfigs, StackNavigatorConfig)
);
// #flow
// AppWithNavigationState
import * as React from 'react';
import codePush from 'react-native-code-push';
import OneSignal from 'react-native-onesignal';
import { connect } from 'react-redux';
import DeviceInfo from 'react-native-device-info';
import PropTypes from 'prop-types';
import {
createReactNavigationReduxMiddleware,
createReduxContainer
} from 'react-navigation-redux-helpers';
import { createAppContainer } from 'react-navigation';
import { AppNavigation } from './Navigation';
import { Storage } from '../Utils';
import { NAME } from './constants';
import type { Dispatch } from '../Model';
type IAppWithNavigationProps = {
dispatch: Dispatch
};
const codePushOptions = {
checkFrequency: codePush.CheckFrequency.ON_APP_RESUME
};
const middleware = createReactNavigationReduxMiddleware(state => state[NAME]);
class AppWithNavigationStateObject extends React.PureComponent<
{},
IAppWithNavigationProps
> {
async componentDidMount() {
codePush.notifyAppReady();
codePush.sync({
updateDialog: true,
installMode: codePush.InstallMode.IMMEDIATE
});
const deviceName = await Storage.get('deviceName');
if (!deviceName) {
await Storage.set('deviceName', DeviceInfo.getDeviceName());
}
}
componentWillMount() {
OneSignal.setLocationShared(true);
OneSignal.inFocusDisplaying(2);
}
render(): React.Node {
const { dispatch, [NAME]: state } = this.props;
console.log(this.props);
return <AppNavigation navigation={{ dispatch, state }} />;
}
}
AppWithNavigationStateObject.propTypes = {
dispatch: PropTypes.func.isRequired,
[NAME]: PropTypes.object.isRequired
};
const AppWithNavigationStateInfo = createReduxContainer(AppNavigation);
const AppWithNavigationState = connect(state => ({
[NAME]: state[NAME]
}))(codePush(codePushOptions)(AppWithNavigationStateInfo));
export { AppWithNavigationState, middleware };
// #flow
// navReducer
import { handleActions } from 'redux-actions';
import { NavigationActions, StackActions } from 'react-navigation';
import { REHYDRATE } from 'redux-persist/constants';
import { AppNavigation } from './Navigation';
import {
CHAT_MAIN,
CHAT_MESSAGE_AREA,
NEW_MESSAGE,
FCLAUNCH,
} from './constants';
const { getStateForAction } = AppNavigation.router;
const initialState = getStateForAction(NavigationActions.init);
const getCurrentRouteName = navState => {
if (Object.prototype.hasOwnProperty.call(navState, 'index')) {
console.log(navState);
return getCurrentRouteName(navState.routes[navState.index]);
}
return navState.routeName;
};
const generateNavigationAction = (state, routeName, params = {}) => {
console.log(routeName);
// Don't navigate to the same screen if is already there.
if (getCurrentRouteName(state) === routeName) {
return state;
}
const nextState = getStateForAction(
NavigationActions.navigate({
routeName,
params
}),
state
);
return nextState || state;
};
export default handleActions(
{
// Custom actions types
[CHAT_MAIN]: state => generateNavigationAction(state, CHAT_MAIN),
[FCLAUNCH]: state => generateNavigationAction(state, FCLAUNCH),
[CHAT_MESSAGE_AREA]: state =>
generateNavigationAction(state, CHAT_MESSAGE_AREA),
[NEW_MESSAGE]: state => generateNavigationAction(state, NEW_MESSAGE),
// overwritten action types from react-navigation
[NavigationActions.NAVIGATE]: (state, { routeName }) =>
generateNavigationAction(state, routeName),
[NavigationActions.BACK]: state => {
const nextState = getStateForAction(NavigationActions.back(), state);
return nextState || state;
},
[NavigationActions.INIT]: state => {
console.error(NavigationActions.INIT);
return state;
},
[NavigationActions.RESET]: (state, { routeName }) => {
console.error(NavigationActions.RESET);
StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName })]
});
return state;
},
[NavigationActions.SET_PARAMS]: (state, { key, params }) => {
const nextState = getStateForAction(
NavigationActions.setParams({
params,
key
}),
state
);
return nextState || state;
},
[NavigationActions.URI]: state => {
console.error(NavigationActions.URI);
return state;
},
// Default initialRouteName
[REHYDRATE]: (state, { payload: { auth } }) => {
const isLogged =
auth &&
auth.token &&
auth.token.length !== 0 &&
auth.refreshToken &&
auth.status &&
auth.refreshToken.length !== 0;
const nextState = isLogged
? state
: generateNavigationAction(state, FCLAUNCH);
return nextState;
}
},
initialState
);
```[enter image description here][2]
[1]: https://i.stack.imgur.com/j5dm8.png

So I fixed my issue:
The createReduxContainer helper from react-navigation-redux-helpers expects three key params: { dispatch, state, ...props }, I wasn't passing the dispatch and state directly but as part of the navigation object passed. So I fixed this by passing missing parameters.

Related

useSelector cause infinate loop in useEffect or passed props is not the newest state in redux

When i add columnext into useEffect dependencies it caused a infnate loop,but when i removed
columnext from denpendencies,the prop materialExtValues passed to my child Component MaterialForm is not the newest redux state but the previous state,my child component render the wrong data.I tried my solution on stackoverflow but can't get my except result,I am really confused,Who can help my out?
import React, { useCallback, useEffect, useState } from 'react';
import FormModal from '../../../../components/FormModal/FormModal';
import { FormType, ColumnExt } from '../../../../types';
import {
MaterialValues,
initialMaterialValues,
} from '../MaterialValues/MaterialValues';
import MaterialForm from './MaterialForm';
import { cvtNullToEmpty } from '../../../../helpers/cvtNullToEmpty';
import { useDispatch, useSelector } from 'react-redux';
import { selectColumnExtDataSelector } from '../../../../redux/columnext/columnext.selector';
import {
materialExtValues,
ExtValues,
EXT_KEYS,
} from '../MaterialValues/MaterialValues';
import { fetchColumnextsRequest } from '../../../../redux/columnext/columnext.action';
interface MaterialEditProps {
editItem: string;
initialValues: MaterialValues;
handleClose: () => void;
}
const MaterialEdit: React.FC<MaterialEditProps> = ({
editItem,
initialValues,
handleClose,
}) => {
const dispatch = useDispatch();
const columnexts: ColumnExt[] = useSelector(selectColumnExtDataSelector);
const [extValues, setExtValues] = useState<ExtValues>(materialExtValues);
//get newest extValues
const initExtValues = useCallback(() => {
const colextFormData = new FormData();
colextFormData.append('TableName', 'material');
colextFormData.append('ObjectId', editItem);
dispatch(fetchColumnextsRequest(colextFormData));
}, [editItem, dispatch]);
//combine newest extValues with old extValues
const mergeMaterialExtValues = useCallback(() => {
const materialExtMerge: ExtValues = {};
columnexts.forEach((item) => {
EXT_KEYS.forEach((key) => {
if (item[key] !== '') {
materialExtMerge[`${item.ColumnName}__${key}`] = item[key];
}
});
});
console.log('materialExtMerge', materialExtMerge);
const newExts = Object.assign(materialExtValues, materialExtMerge);
setExtValues((prev) => ({ ...prev, ...newExts }));
console.log('materialExtValues', materialExtValues);
}, [columnexts]);
useEffect(() => {
initExtValues();
}, [initExtValues, columnexts]);
useEffect(() => {
if (columnexts.length > 0 && columnexts[0].ObjectId === editItem) {
mergeMaterialExtValues();
}
}, [mergeMaterialExtValues, editItem, columnexts.length]);
return (
<>
<div className='material-edit'>
<FormModal
title='Edit Material'
iconSrc='/assets/images/icons/material.png'
handleClose={handleClose}
renderDataForm={() => (
<MaterialForm
formType={FormType.EDIT}
editItem={editItem}
materialExtValues={extValues}
initialValues={
(cvtNullToEmpty(initialValues) as MaterialValues) ||
initialMaterialValues
}
handleClose={handleClose}
/>
)}
/>
</div>
</>
);
};
export default MaterialEdit;
The code of selectColumnExtDataSelector is :
import { RootState } from "../rootReducer";
import { createSelector } from "reselect";
export const selectColumnExts = (state: RootState) =>
state.columnext
export const selectColumnExtDataSelector = createSelector(
[selectColumnExts],
columnexts => columnexts.data
)
And ColumnExtReducer code is:
import { ColumnExt } from "src/types"
import { AnyAction } from 'redux';
import { columnextActionType } from "./columnext.types";
export interface ColumnExtState {
data: ColumnExt[],
loading: boolean;
error: string | null;
}
const initialState: ColumnExtState = {
data: [],
loading: false,
error: null
}
const columnextReducer = (state: ColumnExtState = initialState,
action: AnyAction
) => {
switch (action.type) {
case columnextActionType.FETCH_COLUMNEXTS_REQUEST:
return { ...state, loading: true }
case columnextActionType.FETCH_COLUMNEXTS_SUCCESS:
return { ...state, loading: false, data: action.payload }
case columnextActionType.FETCH_COLUMNEXTS_FAILURE:
return { ...state, loading: true, error: action.payload }
default:
return state;
}
}
export default columnextReducer;

Add a load indicator based on the Redux state - react native

How can I add a charging indicator based on the Redux status?
I need to place a loading screen while sending the data.
charging indicator component
import React from 'react';
import { StyleSheet } from 'react-native';
import AnimatedLoader from "react-native-animated-loader";
import {connect} from 'react-redux'
class Loader extends React.Component {
constructor(props) {
super(props);
this.state = {visible: false };
}
// componentDidMount() {
// setInterval(() => {
// this.setState({
// visible: !this.state.visible
// });
// }, 2000);
// }
render() {
const { visible } = this.props;
if (!visible) return outVisible();
return (
<AnimatedLoader
visible={visible}
overlayColor="rgba(255,255,255,0.75)"
source={require("./loader.json")}
animationStyle={styles.lottie}
speed={1}
>
<Text>Carregando...</Text>
</AnimatedLoader>
);
}
}
const styles = StyleSheet.create({
lottie: {
width: 200,
height: 200
}
});
const mapStateToProps = (state) => ({visible: state.visible});
const mapDispatchToProps = dispatch => {
return {outVisible: () => dispatch(setVisible({visible: false}))}
}
export default connect(mapStateToProps,mapDispatchToProps)(Loader)
Action
import { SET_VISIBLE } from './actionsTypes'
export const setVisible = visible => {
return {
type: SET_VISIBLE,
payload: visible
}
}
Reducer
import { SET_VISIBLE } from '../actions/actionsTypes'
const initialState = {
visible: false
}
const reducer = (state = initialState, action) => {
switch(action.type) {
case SET_VISIBLE:
return {
...state,
visible: action.payload.visible
};
default:
return state;
}
}
export default reducer
Store Config
import {
createStore,
combineReducers,
compose,
applyMiddleware
} from 'redux'
import thunk from 'redux-thunk'
import postReducer from './reducers/post'
import userReducer from './reducers/user'
import messageReducer from './reducers/message'
import loadingReducer from './reducers/loading'
const reducers = combineReducers({
user: userReducer,
post: postReducer,
message: messageReducer,
visible: loadingReducer
})
const storeConfig = () => {
return createStore(reducers, compose(applyMiddleware(thunk)))
}
export default storeConfig
actions types
export const USER_LOGGED_IN = 'USER_LOGGED_IN'
export const USER_LOGGED_OUT = 'USER_LOGGED_OUT'
export const SET_MESSAGE = 'SET_MESSAGE'
export const LOADING_USER = 'LOADING_USER'
export const USER_LOADED = 'USER_LOADED'
export const CREATING_POST = 'CREATING_POST'
export const POST_CREATED = 'POST_CREATED'
export const SET_POSTS = 'SET_POSTS'
export const SET_VISIBLE = 'SET_VISIBLE'
app.js
import React, { Component } from 'react'
import { Alert } from 'react-native'
import { connect } from 'react-redux'
import Routes from "./routes";
import { setMessage } from './store/actions/message'
class App extends Component {
componentDidUpdate = () => {
if(this.props.text && this.props.text.toString().trim())
{
Alert.alert(this.props.title || 'Mensagem',this.props.text.toString())
this.props.clearMessage()
}
}
render() {
return (
<Routes />
)
}
}
const mapStateToProps = ({ message}) => {
return {
title: message.title,
text: message.text,
}
}
const mapDispatchToProps = dispatch => {
return {
clearMessage: () => dispatch(setMessage({ title: '', text: '' }))
}
}
export default connect(mapStateToProps, mapDispatchToProps)(App)
Right after the data is sent to the API, I need to return a load indicator to the user, until that data is stored.

Re-rendering the component after dispatching action from non-component JS file

I'm dispatching the action from a non-component JS (utils/index.js) file using store.dispatch(), but after the reducer state change, the component in which that reducer state is connected using mapStateToProps is not being re-rendered,
What am i doing wrong?
Any help would be appreciated
Thanks in advance
I tried searching through out and i went to all the questions and articles which are dispatching the action from a component file.
All the related files
/store/index.js
import { createStore } from "redux";
import rootReducer from "reducers";
store = createStore(rootReducer);
/utils/index.js
import store from './store';
import { toggleShowAlert } from "reducers/alert";
export const customAlert = msg => {
store.dispatch(toggleShowAlert(msg));
}
/views/Nav/index.js
import React, { Component } from 'react';
import { connect } from 'react-redux';
class Nav extends Component {
render() {
....
// component code
....
}
}
const mapStateToProps = state => {
return {
showAlert: state.alert.showAlert
}
}
export default connect(mapStateToProps)(Nav);
/reducer/alert.js
const TOGGLE_SHOW_ALERT = "TOGGLE_SHOW_ALERT";
export const toggleShowAlert = msg => {
return dispatch => {
dispatch({
type: TOGGLE_SHOW_ALERT,
msg
});
};
};
const initialState = {
showAlert: false,
alertMsg: ""
};
const reducer = (state = initialState, action) => {
switch (action.type) {
case TOGGLE_SHOW_ALERT:
return {
...state,
showAlert: !state.showAlert,
alertMsg: state.showAlert ? "" : action.msg
};
default:
return { ...state };
}
}
export default reducer;
another reducer from which that customAlert is being called
/reducers/user.js
import { customAlert } from 'utils';
...other codes...
export const updateAgeGender = (userId, age, gender) => {
return dispatch => {
dispatch(updateButtonLoading());
callAPI("post", `${COMM_BE_URL}/users/update-age-gender`, {
userId,
age,
gender
})
.then(res => {
if (res.status === "SUCCESS") {
dispatch(updateAgeGenderAction(age, gender));
customAlert("Your info has been updated, now u can join");
}
})
.catch(err => {
console.log(err);
dispatch(updateError(SERVER_ERROR_MSG));
});
};
};
After change of showAlert, the Nav Component should re-render, but it's not happening

Call a redux action in a function helper

I'm trying to create an alert component, however for this I need to add an item (from anywhere) to the list of alerts in the state.
I have this code:
alertReducer.js:
import { SET_ALERT, GET_ALERTS, SET_ALERT_SHOWED } from "../actions/types";
const initialState = {
alerts: [
{
id: 0,
title: "teste",
message: "teste",
isShowed: false,
type: "success"
}
]
};
export default function(state = initialState, action) {
switch (action.type) {
case SET_ALERT:
return { ...state, alert: action.payload };
case SET_ALERT_SHOWED:
return {
...state,
alert: state.alerts.map(a =>
a.id === a.payload.id ? (a = action.payload) : a
)
};
case GET_ALERTS:
return { ...state };
default:
return state;
}
}
alertActions.js
import { SET_ALERT, GET_ALERTS, SET_ALERT_SHOWED } from "./types";
import axios from "axios";
export const getAlerts = () => dispatch => {
dispatch({
type: GET_ALERTS,
payload: null
});
};
export const setAlertShowed = alert => dispatch => {
dispatch({
type: SET_ALERT_SHOWED,
payload: null
});
};
export const setAlert = alert => dispatch => {
console.log("set alert:");
this.setState(state => {
state.alert.alerts.push(alert);
return null;
});
dispatch({
type: SET_ALERT,
payload: null
});
};
alerts.js (component)
import React from "react";
import { Link } from "react-router-dom";
import { Modal, ModalHeader, ModalBody, ModalFooter } from "reactstrap";
import {
Panel,
PanelHeader,
PanelBody
} from "./../../components/panel/panel.jsx";
import SweetAlert from "react-bootstrap-sweetalert";
import ReactNotification from "react-notifications-component";
import "react-notifications-component/dist/theme.css";
import PropTypes from "prop-types";
import { connect } from "react-redux";
import { getAlerts, setAlertShowed } from "../../actions/alertActions";
class Alerts extends React.Component {
constructor(props) {
super(props);
this.addNotification = this.addNotification.bind(this);
this.notificationDOMRef = React.createRef();
}
componentWillReceiveProps(nextProps) {
console.log("atualizou alertas");
console.log(this.props);
console.log(nextProps);
}
componentDidMount() {
this.props.getAlerts();
this.showAlerts();
}
showAlerts() {
const { alerts } = this.props;
alerts
.filter(a => !a.isShowed)
.map((a, i) => {
this.addNotification.call(this, a);
a.isShowed = true;
setAlertShowed(a);
});
}
addNotification(alert) {
this.notificationDOMRef.current.addNotification({
title: alert.title,
message: alert.message,
type: alert.type,
insert: "top",
container: "top-right",
animationIn: ["animated", "fadeIn"],
animationOut: ["animated", "fadeOut"],
dismiss: { duration: 2000 },
dismissable: { click: true }
});
}
render() {
const { alerts } = this.props;
return <ReactNotification ref={this.notificationDOMRef} />;
}
}
Alerts.propTypes = {
alerts: PropTypes.array.isRequired,
getAlerts: PropTypes.func.isRequired,
setAlertShowed: PropTypes.func.isRequired
};
const mapStateToProps = state => ({
alerts: state.alert.alerts
});
export default connect(
mapStateToProps,
{ getAlerts, setAlertShowed }
)(Alerts);
So I have this helper I'm trying to do, it would serve so that from anywhere in the application I can trigger addAlert and generate a new alert, but I have no idea how to call the setAlert function inside the alertActions.js, what I was able to do is call the SET_ALERT through the store.dispatch, but apparently this is not triggering the setAlert or I am doing something wrong
import uuid from "uuid";
import { createStore } from "redux";
import { setAlert } from "../actions/alertActions";
import { SET_ALERT } from "../actions/types";
import alertReducer from "../reducers/alertReducer";
export function addAlert(state, title, message, type = "success") {
// const store = createStore(alertReducer);
// const state = store.getState();
const newalert = {
id: uuid.v4(),
title,
message,
isShowed: false,
type: type
};
console.log("state");
console.log(state);
// this.setState(state => {
// state.alert.alerts.push(alert);
// return null;
// });
// store.dispatch({
// type: SET_ALERT,
// payload: newalert
// });
// store.dispatch(setAlert(newalert));
// store.dispatch(SET_ALERT);
// this.setState(prevState => ({
// alert.alerts: [...prevState.alert.alerts, newalert]
// }))
}
PS. My react knowledge is very low yet and English it's not my primary language, if I don't make myself clear please ask anything.
Thank you.
Do like this:
// Create alert which you want to show
const alerts = [
{
id: 0,
title: "teste",
message: "teste",
isShowed: false,
type: "success"
}];
componentDidMount() {
this.props.getAlerts();
this.showAlerts();
// this will call alerts action
this.props.callAlert(alerts );
}
const mapDispatchToProps = dispatch=> ({
callAlert: (alert) => dispatch(setAlert(alert)),
});
export default connect(
mapStateToProps,
mapDispatchToProps,
{ getAlerts, setAlertShowed }
)(Alerts);
Finally! I created the store by adding compose and applyMiddleware, I still have to study how this works best but it worked.
The helper code to add alert looks like this:
import uuid from "uuid";
import { createStore, dispatch, compose, applyMiddleware } from "redux";
import thunk from "redux-thunk";
import { setAlert } from "../actions/alertActions";
import alertReducer from "../reducers/alertReducer";
export function addAlert(title, message, type = "success") {
const store = createStore(alertReducer, compose(applyMiddleware(thunk)));
const newalert = {
id: uuid.v4(),
title,
message,
isShowed: false,
type: type
};
store.dispatch(setAlert(newalert));
}

TypeError: Cannot read property 'value' of undefined When adding a value to an Array with Redux

CounterContainer
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import PropType from 'prop-types';
import Counter from '../components/Counter';
import * as counterActions from '../store/modules/counter';
import * as postActions from '../store/modules/post';
class CounterContainer extends Component {
handleIncrement = () => {
const { CounterActions } = this.props;
CounterActions.increment();
}
handleDecrement = () => {
const { CounterActions } = this.props;
CounterActions.decrement();
}
addDummy = () => {
const { PostActions } = this.props;
console.log(PostActions);
PostActions.addDummy({
content: 'dummy',
userUID: 123,
});
}
render() {
const { handleIncrement, handleDecrement, addDummy } = this;
const { number } = this.props;
return (
<Counter
onIncrement={handleIncrement}
onDecrement={handleDecrement}
addDummy={addDummy}
number={number}
/>
);
}
}
CounterContainer.propTypes = {
number: PropType.number.isRequired,
CounterActions: PropType.shape({
increment: PropType.func,
decrement: PropType.func,
}).isRequired,
};
export default connect(
state => ({
number: state.counter.number,
}),
dispatch => ({
CounterActions: bindActionCreators(counterActions, dispatch),
PostActions: bindActionCreators(postActions, dispatch),
}),
)(CounterContainer);
PostContainer
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
// import { ListItem } from 'react-native-elements';
import { Text } from 'react-native';
import PropType from 'prop-types';
import Post from '../components/Post';
import * as postActions from '../store/modules/post';
class PostContainer extends Component {
refreshing = () => {}
onRefresh = () => {}
renderItem = ({ item }) => (<Text>{item.content}</Text>)
render() {
const { renderItem } = this;
const { postList } = this.props;
return (
<Post
postList={postList}
renderItem={renderItem}
/>
);
}
}
export default connect(
state => ({
postList: state.post.postList,
}),
dispatch => ({
CounterActions: bindActionCreators(postActions, dispatch),
}),
)(PostContainer);
modules/post
import { createAction, handleActions } from 'redux-actions';
const initialState = {
postList: [{
content: 'test',
userUID: 123,
},
{
content: '123123',
userUID: 123123,
},
],
};
const ADD_DUMMY = 'ADD_DUMMY';
export const addDummy = createAction(ADD_DUMMY, ({ content, userUID }) => ({ content, userUID }));
const reducer = handleActions({
[ADD_DUMMY]: (state, action) => ({
...state,
postList: [action.data, ...state.postList],
}),
}, initialState);
export default reducer;
Clicking the button adds a dummy to the postList.
However, when I click the button, I get
TypeError: Can not read property 'content' of undefined error.
I thought I made it the same as the count-up down tutorial.
But Count Up Down works.
Adding a dummy I made does not work.
Where did it go wrong?
Until I click the Add Dummy Data button
The list is worked.
i change action.data -> actions.payload
const reducer = handleActions({
[ADD_DUMMY]: (state, action) => ({
...state,
postList: [action.payload, ...state.postList],
}),
}, initialState);
It is simply a mistake.

Resources