Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Redux DevTools extension.

License

NotificationsYou must be signed in to change notification settings

zalmoxisus/redux-devtools-extension

Repository files navigation

⚠️⚠️⚠️🚨🚨🚨⚠️⚠️⚠️

⚠️⚠️⚠️🚨🚨🚨⚠️⚠️⚠️

Redux DevTools Extension

Join the chat at https://gitter.im/zalmoxisus/redux-devtools-extensionPRs WelcomeOpenCollectiveOpenCollective

Demo

Installation

1. For Chrome

2. For Firefox

3. For Electron

4. For other browsers and non-browser environment

Usage

Note that starting from v2.7,window.devToolsExtension was renamed towindow.__REDUX_DEVTOOLS_EXTENSION__ /window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__.

1. With Redux

1.1 Basic store

For a basicRedux store simply add:

 const store = createStore(   reducer, /* preloadedState, */+  window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() );

Note thatpreloadedState argument is optional in Redux'screateStore.

For universal ("isomorphic") apps, prefix it withtypeof window !== 'undefined' &&.

constcomposeEnhancers=(typeofwindow!=='undefined'&&window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__)||compose;

For TypeScript useredux-devtools-extension npm package, which contains all the definitions, or just use(window as any) (seeRecipes for an example).

constcomposeEnhancers=(windowasany).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__||compose;

In case ESLint is configured to not allow using the underscore dangle, wrap it like so:

+ /* eslint-disable no-underscore-dangle */  const store = createStore(   reducer, /* preloadedState, */   window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()  );+ /* eslint-enable */

Note: Passing enhancer as last argument requiresredux@>=3.1.0. For older versions apply it likehere orhere. Don't mix the old Redux API with the new one.

You don't need to npm installredux-devtools when using the extension (that's a different lib).

1.2 Advanced store setup

If you setup your store withmiddleware and enhancers, change:

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

Note that when the extension is not installed, we’re using Redux compose here.

To specifyextension’s options, use it like so:

constcomposeEnhancers=typeofwindow==='object'&&window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({// Specify extension’s options like name, actionsBlacklist, actionsCreators, serialize...}) :compose;constenhancer=composeEnhancers(applyMiddleware(...middleware),// other store enhancers if any);conststore=createStore(reducer,enhancer);

See the post for more details.

1.3 Useredux-devtools-extension package from npm

To make things easier, there's an npm package to install:

npm install --save redux-devtools-extension

and to use like so:

import{createStore,applyMiddleware}from'redux';import{composeWithDevTools}from'redux-devtools-extension';conststore=createStore(reducer,composeWithDevTools(applyMiddleware(...middleware),// other store enhancers if any));

To specifyextension’s options:

import{createStore,applyMiddleware}from'redux';import{composeWithDevTools}from'redux-devtools-extension';constcomposeEnhancers=composeWithDevTools({// Specify name here, actionsBlacklist, actionsCreators and other options if needed});conststore=createStore(reducer,/* preloadedState, */composeEnhancers(applyMiddleware(...middleware),// other store enhancers if any));

There’re justfew lines of code added to your bundle.

In case you don't include other enhancers and middlewares, just usedevToolsEnhancer:

import{createStore}from'redux';import{devToolsEnhancer}from'redux-devtools-extension';conststore=createStore(reducer,/* preloadedState, */devToolsEnhancer(// Specify name here, actionsBlacklist, actionsCreators and other options if needed));

1.4 Using in production

It's useful to include the extension in production as well. Usually youcan use it for development.

If you want to restrict it there, useredux-devtools-extension/logOnlyInProduction:

import{createStore}from'redux';import{devToolsEnhancer}from'redux-devtools-extension/logOnlyInProduction';conststore=createStore(reducer,/* preloadedState, */devToolsEnhancer(// options like actionSanitizer, stateSanitizer));

or with middlewares and enhancers:

import{createStore,applyMiddleware}from'redux';import{composeWithDevTools}from'redux-devtools-extension/logOnlyInProduction';constcomposeEnhancers=composeWithDevTools({// options like actionSanitizer, stateSanitizer});conststore=createStore(reducer,/* preloadedState, */composeEnhancers(applyMiddleware(...middleware),// other store enhancers if any));

You'll have to add'process.env.NODE_ENV': JSON.stringify('production') in your Webpack config for the production bundle (to envify). If you usecreate-react-app,it already does it for you.

If you're already checkingprocess.env.NODE_ENV when creating the store, includeredux-devtools-extension/logOnly for production environment.

If you don’t want to allow the extension in production, just useredux-devtools-extension/developmentOnly.

Seethe article for more details.

1.5 For React Native, hybrid, desktop and server side Redux apps

For React Native we can usereact-native-debugger, which already includedthe same API with Redux DevTools Extension.

For most platforms, includeRemote Redux DevTools's store enhancer, and from the extension's context menu choose 'Open Remote DevTools' for remote monitoring.

2. Without Redux

Seeintegrations andthe blog post for more details on how to use the extension with any architecture.

Docs

Demo

Live demos to use the extension with:

Also see./examples folder.

Backers

Support us with a monthly donation and help us continue our activities. [Become a backer]

Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site. [Become a sponsor]

License

MIT

Created By

If you like this, follow@mdiordiev on twitter.


[8]ページ先頭

©2009-2025 Movatter.jp