F
F
fronter-up2017-11-12 15:48:13
JavaScript
fronter-up, 2017-11-12 15:48:13

Middleware breaks redux devtools?

Good afternoon! Please tell me why REDUX_DEVTOOLS_EXTENSION breaks when I use middleware?
Who faced such a problem, how to solve it?
Plus, react extension for chrome doesn't work either... I don't understand what it is.
Throws an error Uncaught TypeError: t.apply is not a function
Code store

import {createStore, applyMiddleware} from 'redux'
import thunk from 'redux-thunk'
import rootReducer from 'reducers/index'

const middleware = [thunk];
if(process.env.NODE_ENV !== 'production') {
  middleware.push(window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__())
}


const mapStore = createStore(
  rootReducer,
  applyMiddleware(...middleware)
);

export default mapStore

Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
davidnum95, 2017-11-12
@fronter-up

You need to do it via compose:

const mapStore = createStore(
  rootReducer,
  compose(
    applyMiddleware(thunk),
    window.__REDUX_DEVTOOLS_EXTENSION__  ?  window.__REDUX_DEVTOOLS_EXTENSION__() : f => f,
  )
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question