React、Redux、Immutable - 无法访问 mapStateToProps 中的 JSON 键

React, Redux, Immutable - cannot access JSON key within mapStateToProps

希望是一个非常简单的(这里是 React 新手!)但我似乎无法从 react/redux/immutable reducer 访问 属性 return 状态中的特定键。

考虑以下我希望 return 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
  };
}

这 return 如下:

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.authenticatedstate 对象中,但我无法访问它!

非常感谢任何建议。


编辑 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);

解决方案:好的,感谢我发现 state.api.get 有效的评论:

const mapStateToProps = (state) => {
  return {
    authenticated: state.api.get('authenticated')
  };
};