我使用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”的字段和我的初始状态。
为什么Redux会创建此字段?我可以禁用它吗?我不想创建几个代码块来检查我的代码中带有'0'前缀的字段。
答案 0 :(得分:2)
执行state = [{isAuthenticated: false}]
会使您的default
成为数组