I can pass paramater to the reducer, but I can't pass the same parameter to the function

Hi,
In the code bellow, object {type: ADD} is passed to the reducer, and is received by the reducer as parameter ‘action’.
Correct?
When I try to pass the same parameter (action) to the function addOne, this function remains void.
Why can’t I pass action to the function addOne as parameter? What am I missing?
Many thanks.

Describe your issue in detail here.

  **Your code so far**

const ADD = 'ADD';

const reducer = (state = 0, action) => {
switch(action.type) {
  case ADD:
    return state + 1;
  default:
    return state;
}
};

const store = Redux.createStore(reducer);

// Global count variable:
let count = 0;

// Change code below this line

function addOne (action, count)  {

if (action === true) {
count +=1;
}
}

// Change code above this line

store.dispatch({type: ADD});
console.log(count);
store.dispatch({type: ADD});
console.log(count);
store.dispatch({type: ADD});
console.log(count);
  **Your browser information:**

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

Challenge: Register a Store Listener

Link to the challenge:

You never subscribed this function.

Also, why do you have an argument count? This shadows the global variable.

Also, why are you checking that the action is strictly equal to true? This will never happen, and I don’t think that sort of check is even needed.

I followed your input and code now works. Thanx.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.