Reputation: 21
I'm starting learn React + Redux , I'm doing a simple application for add or remove a counter .
But I have a problem on a reducer . I try a lot of things without result...
Thanks in advance :)
Here is my code :
The reducer :
import * as actionTypes from "../actions/actionTypes"
const counterReducer=(state=0,action)=>{
let newState;
switch (action.type) {
case actionTypes.INCREASE_COUNTER:
return (newState=state+action.payload);
case actionTypes.DECREASE_COUNTER:
return (newState=state-action.payload);
case actionTypes.INCREASE_BY_TWO_COUNTER:
return (newState=state+action.payload);
default:
return state;
}
};
export default counterReducer;
The connection of the reducer ( I know it's not useless but in the furtur will have to combine reducer ) :
import { combineReducers } from "redux";
import counterReducer from "./counterReducer";
const reducers=combineReducers({
counterReducer
});
export default reducers;
index.js :
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import configureStore from './redux/reducers/configureStore';
import {Provider} from "react-redux";
const store=configureStore
ReactDOM.render(
<React.StrictMode>
<Provider store={store}>
<App />
</Provider>
</React.StrictMode>,
document.getElementById('root')
);
Upvotes: 0
Views: 1503
Reputation: 11
project path: /src/redux/reducers/configureStore.js:
import {createStore} from "redux"
import reducers from "./index";
export default function configureStore(){
return createStore(reducers)
}
Upvotes: 0
Reputation: 177
Have a look at this example:
https://redux.js.org/usage/configuring-your-store#the-solution-configurestore
It seems like you are missing a lot here.
Your const store=configureStore
should be const store=configureStore()
and the complete implementation of configureStore function seems to be missing?
In general your error occurs because in your file './redux/reducers/configureStore', there is no default export like: export default configureStore
Upvotes: 1