我尝试在我的本机应用程序的 redux 商店中存储多个对象,但只有一个对象被保存,我是 redux 的新手,我尝试了在 StackOverflow 上找到的很多解决方案,但没有一个有效:/
结果我在我的商店:
"hives": {"hive_id": 12944, "hive_name": null}
Run Code Online (Sandbox Code Playgroud)
我想要的结果(或类似的东西):
"hives": [
1: {"hive_id": 123, "hive_name": "HelloHive"},
2: {"hive_id": 12944, "hive_name": null}]
Run Code Online (Sandbox Code Playgroud)
店铺:
const middleware = [thunk]
export const store = createStore(persistedReducer, applyMiddleware(...middleware));
export const persistor = persistStore(store);
Run Code Online (Sandbox Code Playgroud)
减速机:
const INIT_STATE = {
hives: [],
}
const hiveReducer = (state = INIT_STATE, action) => {
switch (action.type) {
case SET_HIVES:
return {
...state,
hives: action.payload,
};
[...]
Run Code Online (Sandbox Code Playgroud)
动作创建者:
export const setHives = hives => {
return …Run Code Online (Sandbox Code Playgroud)