createListenerMiddlewareadvancedconst listenerMiddleware = createListenerMiddleware()
listenerMiddleware.startListening({
actionCreator: mySlice.actions.someAction,
effect: (action, api) => { console.log('action fired:', action.type) },
})createListenerMiddleware provides a lightweight alternative to sagas for responding to actions with side effects.
Listener middleware lets you run side effects in response to dispatched actions β without sagas or observables.
Challenge: Set up a listener that pushes 'inc fired' to a sideEffects array every time the counter increments.
store.dispatch(counterSlice.actions.inc())
sideEffects // β ['inc fired']