createStoreadvancedconst store = createStore(reducer, applyMiddleware(logger, thunk))
store.dispatch({ type: 'INCREMENT' })
// β logger logs, thunk checks type, state updatesStore enhancers let you wrap createStore to intercept dispatch, enabling middleware, devtools, and more.
A store enhancer wraps createStore to add capabilities (like middleware). The signature is:
const enhancer = createStore => reducer => store
applyMiddleware is Redux's built-in enhancer factory. When createStore receives an enhancer as its second argument it delegates to it:
function createStore(reducer, enhancer) {
if (typeof enhancer === 'function') return enhancer(createStore)(reducer)
// ...normal store creation
}
Challenge: Implement both createStore(reducer, enhancer) and applyMiddleware(middleware).