Write a Counter with Redux: Action is undefined

Tell us what’s happening:

As you can see, I’ve used the console to try and debug what’s going on and it seems that no action is being passed to my reducer. I don’t know why this is, maybe I’m missing something, but this isn’t my first time using Redux and I’m at a loss. Also, when I log the state to the console, I do not get anything like what it should be.

Your code so far


const INCREMENT = 'INCREMENT'; // define a constant for increment action types
const DECREMENT = 'DECREMENT'; // define a constant for decrement action types

const counterReducer = (state, action) => {
    console.log(state, action)
    return state
}; // define the counter reducer which will increment or decrement the state based on the action it receives

const incAction = () => {
    console.log('incAction called')
    return {type: INCREMENT}
    }; // define an action creator for incrementing

const decAction = () => {
    console.log('decAction called')
    return {type: DECREMENT}
}; // define an action creator for decrementing

const store = Redux.createStore((state = 0) => state, counterReducer())
// define the Redux store here, passing in your reducers


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36.

Link to the challenge:

If in doubt, check the docs:

createStore(reducer, [preloadedState], [enhancer])

https://redux.js.org/api/createstore#createstorereducer-preloadedstate-enhancer

First argument to createStore needs to be the reducer and second, the default state. Also, you don’t want to call the reducer, just pass a reference.

const store = Redux.createStore(counterReducer, 0);