Skip to content

Commit c567bb2

Browse files
author
Rob Sharp
committed
Improve installation instructions by adding examples and note on middleware ordering
1 parent b09d171 commit c567bb2

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,47 @@ A live-editing time travel environment for Redux.
2121
npm install --save-dev redux-devtools
2222
```
2323

24+
DevTools is a middleware, which should be added to your middleware stack *after* `applyMiddleware` because `applyMiddleware` is potentially asynchronous. Otherwise, DevTools won't see the raw actions emitted by the Promise middleware etc.
25+
26+
To install, firstly import `devTools` into your App container:
27+
```
28+
import { devTools, persistState } from 'redux-devtools';
29+
import { DevTools, DebugPanel, LogMonitor } from 'redux-devtools/lib/react';
30+
```
31+
32+
Then, add `devTools` to your middleware, and create your store:
33+
```
34+
const finalCreateStore = compose(
35+
applyMiddleware(thunk),
36+
devTools(),
37+
persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/)),
38+
createStore
39+
);
40+
41+
const store = finalCreateStore(reducer);
42+
```
43+
44+
Lastly, include the `DebugPanel` in your page:
45+
```
46+
export default class App extends Component {
47+
render() {
48+
return (
49+
<Provider store={store}>
50+
{() => <CounterApp />}
51+
</Provider>
52+
<div>
53+
<Provider store={store}>
54+
{() => <CounterApp />}
55+
</Provider>
56+
<DebugPanel top right bottom key="debugPanel">
57+
<DevTools store={store} monitor={LogMonitor} />
58+
</DebugPanel>
59+
</div>
60+
);
61+
}
62+
}
63+
```
64+
2465
[This commit](https://github.com/gaearon/redux-devtools/commit/0a2a97556e252bfad822ca438923774bc8b932a4) should give you an idea about how to add Redux DevTools for your app **but make sure to only apply `devTools()` in development!** In production, this will be terribly slow because actions just accumulate forever. (We'll need to implement a rolling window for dev too.)
2566

2667
For example, in Webpack, you can use `DefinePlugin` to turn magic constants like `__DEV__` into `true` or `false` depending on the environment, and import and render `redux-devtools` conditionally behind `if (__DEV__)`. Then, if you have an Uglify step before production, Uglify will eliminate dead `if (false)` branches with `redux-devtools` imports. Here is [an example](https://github.com/erikras/react-redux-universal-hot-example/compare/66bf63fb0f23a3c264a5d37c3acb4c047bf0c0c9...c6515236a1def8a3d2bfeb8f6cd6f0ccdb2f9e1b) of adding React DevTools to a project handling the production case correctly.

0 commit comments

Comments
 (0)