redux combineReducers 的使用和注意方式

本文介绍了Redux中combineReducers的使用,强调了在映射属性时必须包含key以区分不同reducer。通过实例展示了方法的运用,帮助读者掌握如何在实际项目中应用redux、react-redux、react-thunk及combineReducers。
摘要由CSDN通过智能技术生成

学习代码的时候,一定要动手实践,否则根本学不会!


import { createStore, applyMiddleware } from "redux";
import { combineReducers } from "redux"
//引入中间键盘
import logger from "redux-logger"
import thunk from "redux-thunk"

// 两个reducer 我开始测试 combineReducer
function nameReducer(state = { "name": "action" }, action) {
    const type = action.type;
    switch (type) {
        case "get":
            return state;
        default:
            return state;
    }
}
function CountReducer(state = 10, action) {
    const type = action.type;
    switch (type) {
        case "add":
            state++;
            return state;
        case "minus":
            state--;
            return state;
        case "asyncAdd":
            // 我打印这个就是想看下,它咋接收参数的!
            console.log(action);
            state++;
            return state
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值