Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to apply redux developer tools with reduxThunk

here is my code

import React        from "react";
import ReactDOM     from "react-dom";
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import "normalize.css/normalize.css"
import  "./styles/styles.scss";
import { Router, Route, IndexRoute, browserHistory } from 'react-router';
import reduxThunk from 'redux-thunk';
import { composeWithDevTools } from 'redux-devtools-extension';

import AppRouter from './routers/AppRouter';
import reducers from './reducers';
import {AUTH_USER} from "./actions/types";

//
const createStoreWithMiddleware =  applyMiddleware(reduxThunk)(createStore);
const store = createStoreWithMiddleware(reducers);


const token = localStorage.getItem('token');
if(token){
    store.dispatch({type:AUTH_USER});
}

ReactDOM.render(
    <Provider store={store}>
        <AppRouter />
    </Provider>
    , document.getElementById('app'));

so i want to Use redux-devtools-extension package from npm

how can i implement with createStoreWithMiddleware

like image 384
zulqarnain Avatar asked May 17 '18 07:05

zulqarnain


People also ask

How do I use Redux DevTools with NGRX?

After installing the extension, you now should have the Ngrx DevTools available under the "Redux" menu option of your browser development tools (open them with Ctrl+Shift+I in Chrome). After opening the Ngrx DevTools, you will have to reload the application in order to start debugging the application.

How do I use Redux DevTools With react native?

Once the app opened, by using the shortcut cmd+d in the iOS simulator or cmd+m when running in an Android emulator, the Developer Menu should open. Click the “Debug” option. And Voilà! This should get your RNDebugger connected with your application.


1 Answers

Simply wrap the middleware with composeWithDevTools.Like at first import :

import { composeWithDevTools } from 'redux-devtools-extension';

Add all your middleware in an array.For now there is only one.

const middleware = [
    reduxThunk,
];

Then instead of createStoreWithMiddleWare do

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

So the code becomes:

import React        from "react";
import ReactDOM     from "react-dom";
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import "normalize.css/normalize.css"
import  "./styles/styles.scss";
import { Router, Route, IndexRoute, browserHistory } from 'react-router';
import reduxThunk from 'redux-thunk';
import { composeWithDevTools } from 'redux-devtools-extension';

import AppRouter from './routers/AppRouter';
import reducers from './reducers';
import {AUTH_USER} from "./actions/types";


const middleware = [
    reduxThunk,
];

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


const token = localStorage.getItem('token');
if(token){
    store.dispatch({type:AUTH_USER});
}

ReactDOM.render(
    <Provider store={store}>
        <AppRouter />
    </Provider>
    , document.getElementById('app'));

Haven't tested but should work.

like image 197
pritesh Avatar answered Oct 19 '22 21:10

pritesh