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
First of all, you need to define the store in the window
object (You can place it in you configureStore
file):
window.store = store;
Then you only need to write in the console the following:
window.store.getState();
Hop this helps.
The react devtools have changed since my original answer. The new components
tab in chrome's devtools still has the data, but you may have to search a little bit more.
Components
tabstore
to be shownstore
(for me it was the 4th level)$r.store.getState()
If you have react developer tools running you can use $r.store.getState();
with no changes to your codebase.
Note: You have to open the react devtool in your developer tools window first to make this work, otherwise you will get a $r is not defined
error
$r.store.getState();
or $r.store.dispatch({type:"MY_ACTION"})
into your consoleIf you're using Next JS, you can access the store by: window.__NEXT_REDUX_STORE__.getState()
You can also dispatch actions, just look at the options you have in window.__NEXT_REDUX_STORE__
The recommended solution doesn't work for me.
The correct command is:
$r.props.store.getState()
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)
let store = createStore(yourApp);
window.store = store;
Now you can access the store from window.store in the console like this:
window.store.dispatch({type:"MY_ACTION"})