gpt4 book ai didi

javascript - 我的 reducer 返回 undefined 就像它没有被添加到 combineReducers 中一样,但它是

转载 作者:行者123 更新时间:2023-11-30 19:14:09 26 4
gpt4 key购买 nike

一切似乎都很好,我已经调试了一段时间,但我似乎无法理解问题出在哪里

reducers/index.js

// @flow
import { combineReducers } from "redux";
import blocks from "./blocks";
import users from "./users";
import add from "./add";
const rootReducer = combineReducers({
blocks,
users,
add
});
export default rootReducer;

reducers/add.js

// @flow
import AnyAction from "redux";
import * as ActionTypes from "./../constants";

const initialState = {
number: 0
};

export default function Add(state = initialState, action) {
switch (action.type) {
case ActionTypes.ADD:
return Object.assign({}, state, {
number: number + 1
});
default:
return state;
}
}

连接函数

const { navigation, blocks, dispatch, number } = this.props;
.
.
.
const mapStateToProps = state => ({
blocks: state.blocks,
number: state.number
});

export default connect(mapStateToProps)(BlockList);


最佳答案

合并缩减器后,您需要使用合并的缩减器名称在 mapStateToProps 中访问缩减器的状态。而不是:

const mapStateToProps = state => ({
blocks: state.blocks,
number: state.number
});

有这个:

const mapStateToProps = state => ({
blocks: state.blocks,
number: state.add.number
});

现在,使用 state.add.number,您可以访问 add.js reducer 中的数字状态。

我试着在这里重现你的问题:

Edit loving-tharp-fe3ti

关于javascript - 我的 reducer 返回 undefined 就像它没有被添加到 combineReducers 中一样,但它是,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58174466/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com