在调试时,我可以从浏览器控制台访问Redux存储吗? [英] While debugging, can I have access to the Redux store from the browser console?

查看:204
本文介绍了在调试时,我可以从浏览器控制台访问Redux存储吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为我的 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


  1. 打开开发人员工具

  2. 单击React选项卡

  3. 确保提供者节点(或最顶层节点) )被选中

  4. 然后输入 $ r.store.getStat e(); $ r.store.dispatch({type:MY_ACTION})进入你的控制台

  1. open developer tools
  2. click the React tab
  3. ensure the provider node (or topmost node) is selected
  4. then type $r.store.getState(); or $r.store.dispatch({type:"MY_ACTION"}) into your console

这篇关于在调试时,我可以从浏览器控制台访问Redux存储吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆