We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
store.dispatch(action)
let nextState = todoApp(previousState, action);
store.subscribe(listener);
listener
function listerner() { let newState = store.getState(); component.setState(newState); }
第一个参数:mapStateToProps,把store上的数据作为props传递给组件,类似计算属性 第二个参数:mapDispatchToProps,将 action 作为 props 传递给组件,提供一个dispatch功能
给FilterableProductTable组件props上设置一个getProduct的方法,这个方法主要用来获取product 在componentDidMount的时候调用
生成这个getProduct的方法就是通过mapDispatchToProps的回调参数,dispatch一个相应的action,然后actions里获取到products数据,接着把当前state和新的数据扔给reducer,reducer就会处理state和新的值并更新到state中,state中的products得到了更新。
mapStateToProps监控到state发生变化,就同时更新了之前绑定到组件props上的products属性
http://redux.js.org/ reduxjs/redux#291 http://taobaofed.org/blog/2016/08/18/react-redux-connect/
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Redux核心思想
流程分析简介
store.dispatch(action)
let nextState = todoApp(previousState, action);
store.subscribe(listener);
listener
可以获取到状态,然后触发react的view渲染类似function listerner() { let newState = store.getState(); component.setState(newState); }
项目分析
connect作用
第一个参数:mapStateToProps,把store上的数据作为props传递给组件,类似计算属性
第二个参数:mapDispatchToProps,将 action 作为 props 传递给组件,提供一个dispatch功能
获取products的流程:
给FilterableProductTable组件props上设置一个getProduct的方法,这个方法主要用来获取product
在componentDidMount的时候调用
生成这个getProduct的方法就是通过mapDispatchToProps的回调参数,dispatch一个相应的action,然后actions里获取到products数据,接着把当前state和新的数据扔给reducer,reducer就会处理state和新的值并更新到state中,state中的products得到了更新。
mapStateToProps监控到state发生变化,就同时更新了之前绑定到组件props上的products属性
注意点
参考文档
http://redux.js.org/
reduxjs/redux#291
http://taobaofed.org/blog/2016/08/18/react-redux-connect/
The text was updated successfully, but these errors were encountered: