React 相关问题
1、this.props.history传值
2、react 如何监听路由变化
- 分2种情况:
1、普通react组件(指不是通过Route导入的组件)普通组件需要自己定义上下文
staticcontextTypes = {router:PropTypes.shape({history:PropTypes.shape({push:PropTypes.func.isRequired,replace:PropTypes.func.isRequired,createHref:PropTypes.func.isRequired}).isRequired}).isRequired}componentDidMount(){this.context.router.history.listen(()=>{})}
2、Route导入的组件Route组件已经封装好了上下文,并且设置了props可用。
componentDidMount(){this.props.history.listen(()=>{})}
原生js的办法是:
window.addEventListener('hashchange',()=>{ })
React 相关库
1、状态管理
Redux、Redux 中文官网、Redux 中文文档、React Redux
2、异步提交数据中间件:
redux-saga:Redux-Saga、redux-saga 中文网、Redux-saga 用法
redux-thunk:redux-thunk
