0

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')
 );
Faiq Rustamov
  • 11
  • 1
  • 5
  • You can try `export default combineReducers({...});` instead of assigning it to a constant. I've seen this error before. – SakisTsalk Dec 15 '21 at 14:21

2 Answers2

1

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

0

project path: /src/redux/reducers/configureStore.js:

import {createStore} from "redux"
import reducers from "./index";

export default function configureStore(){
    return createStore(reducers)
}
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 03 '22 at 08:14