In the following code, data is (state, action)not transmitted to the gears on combineReducers. It generates an error below. This is probably a small mistake that I am making. JSFiddle Link: https://jsfiddle.net/bengrunfeld/1h0t59uf/
import React from 'react'
import { render } from 'react-dom'
import { combineReducers } from 'redux'
import { Constants } from './constants/constants'
const goal = (state = 0, action) => {
(action.type === Constants.ADD) ?
state + action.payload:
state
}
const target = (state = 0, action) => {
(action.type === Constants.REMOVE)?
state - action.payload:
state
}
const reducer = combineReducers({
goal,
target
})
const state = 10
const newState = reducer(state, {
type: Constants.REMOVE,
payload: 5
})
render(
<div>
<p>{newState}</p>
</div>,
document.getElementById('main')
)
Error message
main.bundle.js:28054 Uncaught Error: Reducer "goal" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined.
at http:
at Array.forEach (native)
at assertReducerSanity (http:
at combineReducers (http:
at Object.<anonymous> (http:
at __webpack_require__ (http:
at Object.<anonymous> (http:
at __webpack_require__ (http:
at module.exports (http:
at http:
source
share