最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How should I log every dispatch call to a Redux store? - Stack Overflow

programmeradmin3浏览0评论

I want to debug my Redux application by logging every action sent to the dispatcher in my the console.

What is generally regarded as the best approach for doing this?

I want to debug my Redux application by logging every action sent to the dispatcher in my the console.

What is generally regarded as the best approach for doing this?

Share Improve this question asked Aug 8, 2016 at 18:08 sdgfsdhsdgfsdh 37.1k30 gold badges156 silver badges290 bronze badges 1
  • github./evgenyrodionov/redux-logger – lux Commented Aug 8, 2016 at 19:23
Add a ment  | 

1 Answer 1

Reset to default 18

You can use a simple logging middleware, like the example in the redux middleware docs:

const logger = store => next => action => {
  console.group(action.type)
  console.info('dispatching', action)
  let result = next(action)
  console.log('next state', store.getState())
  console.groupEnd()
  return result
}

Or use the redux-logger module, which basically does the same thing.

With TypeScript, use this annotation (where TStore is the type-name of the root of your state:

import { Middleware } from 'redux';

  // ...

const logger: Middleware<{},TState> = store => next => action => {
  console.group(action.type)
  // etc
发布评论

评论列表(0)

  1. 暂无评论