Redux 组合减速机

Redux 组合减速机,redux,Redux,使用组合减速机时出错: 对象作为React子对象无效(找到:具有键{todos,counter}的对象)。如果要呈现子对象集合,请改用数组 代码如下: import { createStore } from "redux"; import { combineReducers } from "redux"; import counter from "./reducers/counter"; import todos from "./reducers/todos"; const reducer =

使用组合减速机时出错:

对象作为React子对象无效(找到:具有键{todos,counter}的对象)。如果要呈现子对象集合,请改用数组

代码如下:

import { createStore } from "redux";
import { combineReducers } from "redux";
import counter from "./reducers/counter";
import todos from "./reducers/todos";

const reducer = combineReducers({
  todos,
  counter
});

export default createStore(reducer);


问题是这一行
{this.props.count}
(请再次将此添加到问题中,而不是作为答案)。在这里,您试图渲染从redux映射的整个状态对象,从而导致错误

由于您将
状态
更改为包含两个减速机,而不是像以前那样只包含一个减速机,因此执行
计数:状态
不再是相同的操作。 我猜您打算从计数器还原器中呈现计数

您需要更改访问它的方式。我建议您更改
MapStateTops
功能

const-mapStateToProps=state=>({
计数:state.counter,
待办事项:state.todos
});
然后,要渲染计数,请执行以下操作:


{this.props.count}

你能在React应用程序中使用
createStore(reducer)
的地方发布代码吗?如果不使用联合减缩器,效果会很好。你似乎在代码的其他地方尝试渲染减缩器。问题似乎与此代码无关。