小编Lau*_*yne的帖子

如何在redux store中保存数组对象数据

我尝试在我的本机应用程序的 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)

reactjs react-native redux redux-thunk react-redux

5
推荐指数
1
解决办法
7804
查看次数

标签 统计

react-native ×1

react-redux ×1

reactjs ×1

redux ×1

redux-thunk ×1