react使用总结五:react-redux合并多个Reducer

这篇博客总结了如何在React-Redux中合并多个Reducer,包括分别介绍Reducer1(themeColor.js)和Reducer2(aa.js),并在index.js中进行合并。接着,博主展示了如何在router.js和page1.js中应用合并后的Reducer,特别提醒在mapStateToProps中引用state的主题颜色属性时,应使用state.themeColorReduce.themeColor。
摘要由CSDN通过智能技术生成

1.Reducer1(themeColor.js)

// reducer 优化后================
// 建议使用这中结构

// 1.定义默认数据
let initialState = {
    themeColor: 'red'
}

// 2.Reducer
const themeReducer = (state = initialState, action) => {
    switch (action.type) {
      case 'CHANGE_COLOR':
        return { ...state, themeColor: action.themeColor }
      default:
        return state
    }
}
// 3.导出
export default themeReducer;

2.Reducer2(aa.js)

// reducer 优化后================
// 建议使用这中结构

// 1.定义默认数据
let initialState = {
    aa:'99999'
}

// 2.Reducer
const aaReducer = (state = initialState, action) => {
    switch (action.type) {
      case 'CHANGE_AA':
        return { ..
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值