My middleware looks like
export const timerMiddleware = store => next => action => {
if (action.type === "START_TIMER") {
// console.log("timer");
action.interval = setInterval(
() => store.dispatch({ type: "TICK", currentTime: Date.now() }),
1000
);
debugger;
} else if (action.type === "STOP_TIMER") {
//console.log(store);
debugger;
console.log(action.interval);
clearInterval(action.interval);
}
next(action);
};
on Start timer the clock is ticking, but on stop_timer i loose the reference of setInterval. so unable to stop the clock. what i am missing here. https://codesandbox.io/s/xrmnwr7y8z