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')
);