Sorry for the silly question but i do not know how to combine together my existing redux store definition with applyMiddleware.
This is my current working code:
const store = createStore(
combineReducers({
...reducers,
routing: routerReducer
})
)
I would like to add this middleware somehow to my store definition:
applyMiddleware(...thunk)
My solution does not work, I get a "TypeError: dbg is undefined" in the web browser:
const store = createStore(
applyMiddleware(...thunk),
combineReducers({
...reducers,
routing: routerReducer
})
)
Could you please give me a quick help? Thank you.
You can create store using Redux toolkit very easily. From Redux Toolkit you can use configureStore which wraps around createStore API and handle the store setup automatically.
Try this
createStore(
combineReducers({
...reducers,
routing: routerReducer
}),
applyMiddleware(thunk)
)
Syntax:
createStore(reducer, [preloadedState], [enhancer])
Enhancer
must be the last parameter for createStore()
Read more from here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With