DEV Community

Cover image for Redux Devtools: Actions Stack Trace
Nero Adaware
Nero Adaware

Posted on • Edited on

Redux Devtools: Actions Stack Trace

I recently watched on Youtube Mark Erikson's talk 'The State of Redux' in Reacthaton 2019. Apart from talking about the current state of redux(Yes!! Redux is not dead) he also spoke about a new feature added to the Redux developer tools. This is called the action stack trace, it helps you track where a particular Redux action was dispatched from. This feature is disabled by default when enabled a Trace tab is added to your Redux devtools and when you click on a particular action it shows you the stack trace of where that action was dispatched from.

I think this is a big addition to the Redux devtools because not long ago I had to deal with a bug where an action was dispatched in my application but I didn't know where or what dispatched that action.

Action stack trace demo

The above image was gotten from Redux Devtools Extension Docs

To enable this feature set the trace option to true when you are setting up the redux devtools. Examples are below on are to enable this feature.



// Without middleware

//import { composeWithDevTools } from "redux-devtools-extension";
//import * as actionCreators from "./actions/index";

const composeEnhancers = composeWithDevTools({
  actionCreators,
  trace: true,
  traceLimit: 25,
})
const store = createStore(reducer, composeEnhancers())


Enter fullscreen mode Exit fullscreen mode


// With thunk middleware 

//import { composeWithDevTools } from "redux-devtools-extension";

const composeEnhancers = composeWithDevTools({ 
    actionCreators, 
    trace: true, 
    traceLimit: 25 
}); 
const store = createStore(reducer, preloadedState, composeEnhancers(
    applyMiddleware(invariant(), thunk) 
));


Enter fullscreen mode Exit fullscreen mode


// With redux-saga middleware 
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ &&

    window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({ 
    trace: true, 
    traceLimit: 25 
}) || compose; 
const store = createStore( reducer, composeEnhancers(applyMiddleware(sagaMiddleware))


Enter fullscreen mode Exit fullscreen mode

You can check out the docs for examples

I use create react app for most of my React application so I don't need any additional setup but if you setup your own application using webpack configuration you will need to set the devtool in your webpack config to source-map for development. This helps Redux devtools provide a mapping between the original code and the transformed source code.

Top comments (3)

Collapse
 
markerikson profile image
Mark Erikson

Just now seeing this post. Glad my talk was informative, and glad that the "action stack trace" feature is useful for you!

Collapse
 
teddcp2 profile image
teddcp2

hey what is actionCreator exacly? is it getting imported from somewhere?

Collapse
 
teddcp2 profile image
teddcp2

Got it... all the actions :)

import * as actionCreators from '../actions/counter'; 
Enter fullscreen mode Exit fullscreen mode

github.com/zalmoxisus/redux-devtoo...