- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我刚刚开始接触 redux,并且在一段时间内遇到了预加载状态的问题。
当使用单个 reducer 时,我使用了以下代码,并且它曾经工作正常。相关片段::
const head = (state = {}, action) => {
switch (action.type) {
case 'TOGGLE_VISIBLITY':
if (state.head.content !== action.id) {
return state
}
state.body.visible = !state.body.visible;
return state;
default:
return state
}
}
const heads = (state = [], action) => {
switch (action.type) {
case 'TOGGLE_VISIBLITY':
state.body = state.body.map(t =>
head(t, action)
);
}
return state;
}
export const store = createStore(heads, config);
但是我只是将其更改为combinerReducers,并且它开始抛出JS错误。
Unexpected keys "head", "body" found in preloadedState argument passed to createStore. Expected to find one of the known reducer keys instead: "heads". Unexpected keys will be ignored.
我的改变是::
const plannerApp = combineReducers({
heads
});
export const store = createStore(plannerApp, config);
如果您想查看完整代码,请访问here .
任何帮助都是非常值得赞赏的。预先非常感谢...我感谢您的时间和努力...
最佳答案
简而言之,预加载状态需要与 reducer 的结构相匹配。自从您改用 combineReducers
以来,您的状态树结构已经发生了变化。您现在有一个顶级键 heads
,它有一个子键 body
,因此您可能需要更新您的 config
,如下所示:
export default {
heads: {
body: {
...
现在,config
对象包含head
和body
的顶级键,它们在顶级没有条目你的状态树。
关于javascript - 在redux中,使用combineReducers预加载状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42241153/
请告诉我我做错了什么?配置商店.js: import {configureStore, combineReducers} from "@reduxjs/toolkit"; import pokemon
请告诉我我做错了什么?配置商店.js: import {configureStore, combineReducers} from "@reduxjs/toolkit"; import pokemon
我正在使用 combineReducers在我的 React TypeScript 应用中: // combinedReducer.ts import { combineReducers } from
我有bookManageReducer.jsx: import { combineReducers } from 'redux' import { REQUEST_BOOKS_PAGE, RE
我是 Redux 的新手。 我一直在阅读它的'Reducers documentation , 遇到了我似乎无法理解的他们的 combineReducers 函数。 他们注意到: All combin
我试图嵌套我的 reducer 以提供这种结构: state: { data: { dataSetOne: { items: [], filter: {
我有一个 redux 存储,到目前为止,它非常简单,只需要一个 reducer 文件。但是我现在需要把它分开。使用 combineReducers{reducerOne, reducerTwo} 是我
在 egghead.io series on Redux 的第 16 课中,在看 Dan 是如何做到的之前,我尝试实现了自己的 combineReducers 函数。我得到了以下。我尝试在像这样传入的
尝试将我的单个 reducer 拆分为不同的 reducer combineReducers是 redux 为此目的提供的便利功能。 combineReducers尽管使用至少每个第一级状态键的缩减器
我现在在 Redux 的 combineReducers 上收到以下错误。 A 缺少类型注释。 A 是在函数类型 [1] 中声明的类型参数,并在调用 combineReducers [2] 时隐式实例
当我直接使用 redux reducer 时,我得到了预期的状态: import cheese from 'reducers/cheese.js'; const store = createStore
我想要的是根 reducer 结合其他 reducer ,并听取额外的 Action 。我找到了文档,但我无法获得任何信息。 这是一些伪代码。 const root1 = combineReducer
当我使用定义的名称导入 reducers 时,我的应用程序工作正常,但是当我使用 combineReducers 时,它返回空白页。 store.js代码是: import { createStore
我之前的 React-Redux 实现工作正常,但在我尝试使用单独的文件实现 combineReducer 函数后,抛出了一个我不太明白的错误。希望你们中的一些人能帮助我! 错误:未捕获的类型错误:t
在下面的代码中,数据 (state, action) 没有被 combineReducers 传递给 reducers。它会产生以下错误。可能只是我犯的一个小错误。链接到 JSFiddle:https
更新 感谢@Dominic Tobias 和@gabdallah 发现了我令人尴尬的错误。 当然是正确答案; so try checking action.payload. 关于 switch 语句和
在Redux basics tutorial关于 Reducers 的部分我不太明白以下语法如何推断出应用程序状态的哪个子集要传递给调用 combineReducers 时引用的每个 reducer。
Redux 文档建议使用 normalizr像这样设计状态的形状: { entities: { cards: { 42: { id: 42, t
这是我的商店代码 import { combineReducers, createStore } from "redux"; import counterReducer from "./../Cou
将两个 reducers 组合在一起(EditButton 和 TodoApp)后,我的应用程序每次开始崩溃。在此之前,当我只使用一个 reducer TodoApp 时,我对 reducers 没有
我是一名优秀的程序员,十分优秀!