Uh oh! Looks like there's an error with the Store reducer. The argument passed to combineReducers needs to be an object with valid reducers.
I'm having trouble setting up a Store for my app and I can't figure out where I went wrong. Could someone help me identify the issue and suggest how to resolve it?
store
import { configureStore } from '@reduxjs/toolkit';
import rootReducers from './reducers';
const store = configureStore({
reducer: rootReducers,
});
export default store;
reducer
import handleCart from './handleCart';
import { combineReducers } from 'redux';
const rootReducers = combineReducers({
handleCart,
});
export default rootReducers;
const cart = [];
const handleCart = (state = cart, action) => {
const product = action.payload;
switch (action.type) {
case ADDITEM:
// Check if product already exists
const exist = state.find(x => x.id === product.id);
if (exist) {
return state.map(x =>
x.id === product.id ? {...x, qty: x.qty + 1} : x,
);
} else {
const product = action.payload;
return [
...state,
{
...product,
qty: 1,
},
];
}
break;
case REMOVEITEM:
const exist1 = state.find(x => x.id === product.id);
if (exist1.qty === 1) {
return state.filter(x => x.id !== exist1.id);
} else {
return state.map(x =>
x.id === product.id ? {...x, qty: x.qty - 1} : x,
);
}
break;
default:
break;
}
};