在React的Redux中,如何方便的查看next state的状态?
来源:互联网 发布:域名注册好了怎么使用 编辑:程序博客网 时间:2024/06/05 16:06
我们在React 的开发过程中,通常会引用Redux,作为一个事件,数据和视图的一个解耦框架,从而更加有利于代码的工程实践和维护。使用Reducer的时候,我们通过mapStateToProps方法或者mapDispatchToProps方法,把reducer中维护的state映射到React组件的props上去。但是有的时候,有用reducer里面定义的结构比较复杂,里面有好几层嵌套,我在使用被映射过的props的时候,往往不知道,其到底把state中的那些对象和属性映射过来了,那么有没有什么解决的方法呢?
笔者经过实践,发现,其实又一个很好的方法,可以帮助我们快速的判断和定位,那就是在主的redux的store里面把state里面的对象写入到log里面去,代码如下:
import { createStore, applyMiddleware } from 'redux';import thunk from 'redux-thunk';import reducers from '../reducers/index-reducers.js';const logger = (store) => (next) => (action) => { console.group(action.type); console.info('dispatching', action); if(typeof action !== "function"){ console.log('dispatching:', action); } let result = next(action); console.log('next state', store.getState()); console.groupEnd(action.type); return result;}const IndexStore = createStore( reducers, applyMiddleware(logger, thunk));export default IndexStore;
就是其中的下面的这行代码大大的帮助了我。
console.log('next state', store.getState());
特意个大家分享一下,希望能够帮助到大家。
阅读全文
0 0
- 在React的Redux中,如何方便的查看next state的状态?
- React和Redux的状态处理
- 使用JWT验证在我们的React&Redux应用中
- React和Redux的连接react-redux
- React和Redux的连接react-redux
- React和Redux的连接react-redux
- React和Redux的连接react-redux
- React和Redux的连接react-redux
- React和Redux的连接react-redux
- React和Redux的连接react-redux
- React、Redux、React-Redux的一些理解
- react-redux的理解
- React-Redux 的用法
- React-Redux 的用法
- react中react-redux和react-router4.*的配合使用
- react-native的state
- React实战-一个比Redux更轻量级的state管理库(Kea)
- React中prop和state的区别
- NO.27 re
- leetcode习题解答:10. Regular Expression Matching
- JAVA基础面试(二)
- Vulkan规范:第八章 8.11 ~ 8.13
- seo优化中怎么做聚合页-优秀聚合页参考
- 在React的Redux中,如何方便的查看next state的状态?
- Vulkan规范:第九章
- 【推荐系统】概率矩阵分解 probabilistic matrix factorization
- C#初识8 多态之接口(interface)
- 【AngularJS】数据绑定(双向绑定)
- Vulkan规范:第九章 9.1
- 推荐系统(RS),麻雀虽小,五脏俱全
- 数组初始化,清空数组,数组元素逆置
- 图像颜色空间转换-CSC