Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create store with react-redux

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.

like image 356
zappee Avatar asked Jan 13 '17 20:01

zappee


People also ask

Can we use createStore in Redux?

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.


1 Answers

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

like image 170
Jyothi Babu Araja Avatar answered Nov 05 '22 01:11

Jyothi Babu Araja