18

I have a problem with redux chrome extension.

I have the following code in my configureStore.js file :

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

export default function configureStore(initialState){
  return createStore(
    rootReducer,
    initialState,
    applyMiddleware(thunk),
    window.devToolsExtension ? window.devToolsExtension() : f => f
  );
}

I've added window.devToolsExtension ? window.devToolsExtension() : f => f like on the tutorial.

But when I try to run the extension I get

enter image description here

EDIT

import 'babel-polyfill';
import React from 'react';
import {render} from 'react-dom';
import {Router, browserHistory} from 'react-router';
import routes from './routes';
import '../node_modules/bootstrap/dist/css/bootstrap.min.css';
import './assets/sass/main.scss';
import '../node_modules/font-awesome/css/font-awesome.css';

import {loadCourses} from './actions/courseActions';
import {loadAuthors} from './actions/authorActions';
import {Provider} from 'react-redux';
import configureStore from './store/configureStore';

const store = configureStore();
store.dispatch(loadCourses());
store.dispatch(loadAuthors());

render(
  <Provider store={store}><Router history={browserHistory} routes={routes}/></Provider>, document.getElementById("app")
);

Any advice?

Boky
  • 11,554
  • 28
  • 93
  • 163
  • 1
    While this is certainly on topic on SO, I'm not sure it's on topic in [tag:google-chrome-extension].. (since that's not for questions that simply relate to extensions, but questions about extension **development**) – Xan May 30 '16 at 13:27
  • Could you also add the part of the code where you create the store and pass it to the provider? – larrydahooster May 30 '16 at 15:58
  • @larrydahooster Sure. I updated my question. – Boky May 30 '16 at 16:07
  • Thanks for updating. Looks okay for me. Sorry can't help out there :( – larrydahooster May 30 '16 at 20:38

8 Answers8

39

I've got the solution from here.

The right code is :

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

export default function configureStore(initialState){
  return createStore(
    rootReducer,
    initialState,
    compose(
      applyMiddleware(thunk),
      window.devToolsExtension ? window.devToolsExtension() : f => f
    )
  );
}
Boky
  • 11,554
  • 28
  • 93
  • 163
19

Ok, just checking the official repository of the Redux Dev Tools I found they recommend to use __REDUX_DEVTOOLS_EXTENSION__ instead of devToolsExtension as you are using.

So after just this update my code and de connectino with the plugin start working like a charm.

Here a sample code if it helps anyone:

const enhancers = compose(
  window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
  );

const store = createStore(
  rootReducer,
  defaultState,
  enhancers
);
robertovg
  • 1,018
  • 11
  • 16
  • 2
    Thank you @robertovg. I was getting error mentioning, compose not defined. To solved we need to import from redux. Example : import { createStore, compose } from 'redux'; – Johnson Samuel Mar 30 '18 at 15:49
3

There is a simpler solution now from the redux-devtools folks. See:

section 1.3 Use redux-devtools-extension package from npm at https://github.com/zalmoxisus/redux-devtools-extension

basically, if you npm install there redux-devtools-extension you can:

import { createStore, applyMiddleware } from 'redux';
import { composeWithDevTools } from 'redux-devtools-extension';

const store = createStore(reducer, composeWithDevTools(
  applyMiddleware(...middleware),
  // other store enhancers if any
));

In my case I only have one piece of middleware (redux-thunk) but I have an initialState so it looks like this:

const store = createStore(reducer, initalState, composeWithDevTools(applyMiddleware(thunk)))
store.subscribe(() => console.log("current store: ", JSON.stringify(store.getState(), null, 4)))
Dr.YSG
  • 7,171
  • 22
  • 81
  • 139
2

For anyone that none of these worked for, try restarting your server. I had tried for a while and then decided to restart my server. That solved it for me

1

As it is given in the original repository https://github.com/zalmoxisus/redux-devtools-extension, you must import compose as a named import and run this compose method by adding the applyMiddleware method as an input;

import { createStore, applyMiddleware, compose } from 'redux';
...
...
+ const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
+ const store = createStore(reducer, /* preloadedState, */ wcomposeEnhancers(
    applyMiddleware(...middleware)
));
0

If anyone followed the same (or similar) boilerplate server-side rendering React app setup that I did, you may want to be sure if there are separate server and client files that use createStore(). In my case there were, and I spent a lot of time playing with the server file, when it needed to go into the client file.

Probably not the best way to do it, but alas, the boilerplate code I used did it that way.

daleyjem
  • 2,335
  • 1
  • 23
  • 34
0

I write a simple solution in the hope that it will be useful (It is not a definitive solution):

  1. I have to right click on Redux Devtools Extension

  2. Open Remote DevTools

  3. Then change the Settings to use the custom server which is localhost:3000

And it works

Domenico Zinzi
  • 954
  • 10
  • 18
-2

I am late but may help someone, my solution was to use connect the component

import {connect} from 'react-redux'
...
class MyComponent extends Cmponent{
...
}
export default connect()(MyComponent)
Mujtaba Zaidi
  • 629
  • 1
  • 6
  • 14