在调试时,我可以从浏览器控制台访问Redux存储吗? [英] While debugging, can I have access to the Redux store from the browser console?
问题描述
我已经为我的 redurs
进行了单元测试,正如我所说的那样。但是,当我在浏览器中调试时,我想检查我的操作是否已被正确调用,以及状态是否已相应修改。
I have unit tests for my reducers
, as I'm supposed so have. However, when I'm debugging in the browser, I want to check if my actions have been called correctly and whether the state has been modified accordingly.
我正在寻找类似于:
window._redux.store
...在浏览器中我可以在控制台上键入它并检查事情的进展情况。
... in the browser so I can type that on the console and check how things are going.
怎么能我实现了这个目标吗?
How can I achieve that?
推荐答案
如果你有反应开发工具,你可以使用 $ r.store。 getState();
没有更改代码库。
If you have react developer tools running you can use $r.store.getState();
with no changes to your codebase.
注意:你必须首先在开发人员工具窗口中打开react devtool以使其工作,否则你将得到 $ r未定义
错误
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
- 打开开发人员工具
- 单击React选项卡
- 确保提供者节点(或最顶层节点) )被选中
- 然后输入
$ r.store.getStat e();
或$ r.store.dispatch({type:MY_ACTION})
进入你的控制台
- open developer tools
- click the React tab
- ensure the provider node (or topmost node) is selected
- then type
$r.store.getState();
or$r.store.dispatch({type:"MY_ACTION"})
into your console
这篇关于在调试时,我可以从浏览器控制台访问Redux存储吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!