Writing Redux store enhancers
A Redux store enhancer is a higher-order function that takes a store creator function and returns a new enhanced store creator function. The createStore
method is a store creator which has the following signature:
createStore = (reducer, preloadedState, enhancer) => Store
While a store enhancer function has the following signature:
enhancer = (...optionalArguments) => ( createStore => (reducer, preloadedState, enhancer) => Store )
It may look a bit difficult to understand now, but you don't really have to worry if you don't get it at first because you will probably never need to write a store enhancer. The purpose of this recipe was simply to help you to understand their purpose in a very simple way.
Getting ready
In this recipe, you will create a store enhancer to expand the functionality of Redux by allowing the definition of reducer functions in a Map
JavaScript native object. First, create a new package.json
file with the following content:
{ ...