I have a simple two button on the web page one for increment and one for decrements an integer.
Once i click on + button it will add 1 to the current value.
Below is my Reducer and i have wrapped "INCREMENT" with a setTimeout
and when i click on + button i'am expecting to see 1 on the page after 2 secs, but it gives me 77 as soon as click happens without waiting for 2 secs, Why this happens, why 77 every time?
p.s. I might need a middleware to handle this async action, but i m trying to understand whats going on
Thank you
const mathReducer = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return setTimeout(() => {
state = state + 1
}, 2000)
case 'DECREMENT':
return state - 1
default:
return state
}
}
export default mathReducer