美文网首页
Redux-004-使用 react-redux

Redux-004-使用 react-redux

作者: 空乱木 | 来源:发表于2019-10-28 21:43 被阅读0次

1- 定义actions 只是单纯的做数据传递

import { INCREMENT, DECREMENT } from '../constants';//省略index.js

export const increment = (name) => {
return {
type: INCREMENT,
name
}
};

export const decrement = () => {
return {
type: DECREMENT
}
};

2- 绑定事件
const {dispatch} = this.props;
onClick={ ()=> dispatch(increment("River"))}

  • 事件和页面分离;
    在想添加事件的地方添加事件

3- reducers处理逻辑的聚合

  • 传入旧的state和action返回新的state
    import rootReducer from './reducers’;
  • 事件分离
  • state数据聚合

相关文章

网友评论

      本文标题:Redux-004-使用 react-redux

      本文链接:https://www.haomeiwen.com/subject/hvjivctx.html