While debugging, can I have access to the Redux store from the browser console?

前端 未结 9 1237
难免孤独
难免孤独 2020-12-12 14:01

I have unit tests for my reducers. However, when I\'m debugging in the browser, I want to check if my actions have been called correctly and whether the state h

9条回答
  •  萌比男神i
    2020-12-12 14:47

    In case you would like to see store state for debugging you could do this:

    #import global from 'window-or-global'
    const store = createStore(reducer)
    const onStateChange = (function (global) {
      global._state = this.getState()
    }.bind(store, global))
    store.subscribe(onStateChange)
    onStateChange()
    console.info('Application state is available via global _state object.', '_state=', global._state)
    

提交回复
热议问题