React,Redux,Immutable-无法访问mapStateToProps中的JSON密钥

时间:2019-03-11 09:39:31

标签: reactjs redux state immutable.js

希望这是一个非常简单的按钮(在这里反应新手!),但我似乎无法访问由react / redux / immutable reducer返回的state属性内的特定键。

考虑以下要返回state.api.authenticated值的地方:

function mapStateToProps(state) {
  console.log('DEBUG 1: ', JSON.stringify(state));
  console.log('DEBUG 2: ', JSON.stringify(state.api));
  console.log('DEBUG 3: ', JSON.stringify(state.api.authenticated));
  return {
    authenticated: state.api.authenticated
  };
}

这将返回以下内容:

DEBUG 1:  {"modals":{},"routing":{"locationBeforeTransitions":null},"api":{"loading":false,"requests":{},"errors":{"last":null},"data":{"articles":[]},"authenticated":true},"articles":{"to_read_count":0},"form":{"signin":{"registeredFields".... (redacted for brevity)

DEBUG 2:  {"loading":false,"requests":{},"errors":{"last":null},"data":{"articles":[]},"authenticated":true}

DEBUG 3:  undefined

很明显state.api.authenticated位于state对象中,但是我无法访问它!

任何建议都值得赞赏。


编辑1:Reducer初始状态定义:

const initialState = Map({
  loading: false,
  requests: OrderedMap({}),
  errors: Map({
    last: null
  }),
  data: Map({
    articles: List()
  }),
  authenticated: false
});

减速器设置值:

case AUTH_USER:
      return state.set('authenticated', true);

0 个答案:

没有答案