I receive an error when following a YouTube crash course on redux:
redux.js:158 Uncaught Error: Expected the root reducer to be a function. Instead, received: ''
at createStore (redux.js:158:1) | at redux.js:682:1 | at createStore (redux.js:154:1) | at ./src/state/store.js (store.js:5:1)
I suspect the error is inside store.js, but I'm not able to debug it. And, why '' is returned? Very much grateful for your help.
store.js
import { legacy_createStore as createStore, applyMiddleware } from "redux";
import reducers from "./reducers/index"
import thunk from "redux-thunk"
export const store = createStore(
reducers,
{},
applyMiddleware(thunk)
)
reducers/index.js
import { combineReducers } from "redux";
import accountReducer from "./accountReducer";
const reducers = combineReducers ({
account : accountReducer
});
export default reducers;
reducers/accountReducer.js
const reducer = (state = 0, action) => {
switch (action.type) {
case "deposit":
return state + action.payload;
case "withdraw":
return state - action.payload;
default:
return state
}
};
export default reducer;
App.js
import {useSelector, useDispatch} from "react-redux"
import {bindActionCreators} from "redux"
import {actionCreators} from "./state/index"
function App() {
const account = useSelector((state) => state.acoount );
const dispatch = useDispatch()
const {depositMoney, withdrawMoney} = bindActionCreators(actionCreators, dispatch)
return (
<div className="App">
<h1>{account}</h1>
<button onClick={() => depositMoney(1000)}>Deposit</button>
<button onClick={() => withdrawMoney(1000)}>Withdraw</button>
</div>
);
}
export default App;
index.js
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App' ;
import reportWebVitals from './reportWebVitals';
import { Provider } from 'react-redux';
import {store} from './state/store'
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<Provider store = {store}>
<App />
</Provider>
</React.StrictMode>
);
reportWebVitals();