Reputation: 484
My react app when ever I start my react app it gives an error of action undefined. Which I used in my reducer in switch(action.type) and I am getting the issue I searched for it but the syntax was the same or maybe I am doing mistake somewhere else but I am unable to figure it out.
Action.js
export function createUser(details)
{
return{ type: 'CREATE_USER',details}
}
Reducer.js
export default function userReducer(state= initialState, action) {
switch (action.type) {
case 'CREATE_USER':
return[...state,
Object.assign({}, action.details)
];
default:
return state;
}
}
index.js form combine reducers
import {combineReducers} from 'redux';
import userReducer from './Reducers';
const rootReducer = combineReducers({
detail: userReducer
});
export default rootReducer;
ConfigureStore.js
import rootReducer from "../reducers/index";
import {createStore} from 'redux';
export default function (initialState) {
return createStore(
initialState,
rootReducer,
)
}
Upvotes: 1
Views: 221
Reputation: 5075
As stated in the comments, you need to reverse the order in which you pass initialState
and rootReducer
to createStore
: i.e. change your ConfigureStore.js to
import rootReducer from "../reducers/index";
import { createStore } from 'redux';
export default function (initialState) {
return createStore(
rootReducer,
initialState,
)
}
Upvotes: 1