为什么redux使用'0'名称在商店中创建状态?

时间:2018-01-26 15:52:21

标签: javascript reactjs redux react-redux

我使用React,Redux和Redux-saga。对于Reducer,我使用combineReducers()。在reducer中我设置了这样的初始状态:

const authentication = (state = [{isAuthenticated: false}], action) => 
  {  
     switch (action.type) {
       case USER_LOGIN_TRY:
         return Object.assign({}, state, userLogin(action.email))
     default:
       return state;
     }
  }

这将使用变量authentication创建isAuthenticated对象。但是,当我从状态检索此值时,在设置初始状态后,我在Redux DevTools(和控制台中)中看到redux创建了名为“0”的字段和我的初始状态。

Why redux create this field? Can i disable this?

为什么Redux会创建此字段?我可以禁用它吗?我不想创建几个代码块来检查我的代码中带有'0'前缀的字段。

1 个答案:

答案 0 :(得分:2)

执行state = [{isAuthenticated: false}]会使您的default成为数组