React native React native、redux和reselect-选择器返回不正确的数据

React native React native、redux和reselect-选择器返回不正确的数据,react-native,redux,reselect,React Native,Redux,Reselect,我有以下代码: select.js: export const getNavigationRoutes = state => state.navigation.routes export const getNavigationIndex = state => state.navigation.index export const getNavigationTab = createSelector( [getNavigationRoutes, getNavigationIndex

我有以下代码:

select.js

export const getNavigationRoutes = state => state.navigation.routes
export const getNavigationIndex = state => state.navigation.index

export const getNavigationTab = createSelector(
  [getNavigationRoutes, getNavigationIndex],
  (routes, index) => (routes[index])
)

export const getBackNavSupported = createSelector(
  getNavigationTab, nevTab => nevTab.index !== 0
)
import {connect} from 'react-redux'
import AppView from './AppView'
import { getBackNavSupported } from '../selectors

export default connect(
  state => ({
    backNavSupported: getBackNavSupported(state),
  }))
)(AppView)
viewController.js

export const getNavigationRoutes = state => state.navigation.routes
export const getNavigationIndex = state => state.navigation.index

export const getNavigationTab = createSelector(
  [getNavigationRoutes, getNavigationIndex],
  (routes, index) => (routes[index])
)

export const getBackNavSupported = createSelector(
  getNavigationTab, nevTab => nevTab.index !== 0
)
import {connect} from 'react-redux'
import AppView from './AppView'
import { getBackNavSupported } from '../selectors

export default connect(
  state => ({
    backNavSupported: getBackNavSupported(state),
  }))
)(AppView)
我的状态从

{
  "index": 1,
  "key": "root",
  "routes": [
    {
      "key": "HomeTab",
      "title": "Home",
      "index": 0,
      "routes": [ /* .... */ ]
    },
    {
      "key": "FamilyTab",
      "title": "Family",
      "index": 0,
      "iconName": "people",
      "routes": [ /* .... */ ]
    },
  ]
}

我在
AppView
中使用
backNavSupported
,但是当我在状态更改后检查
backNavSupported
的值时,我得到了
false
,这对我来说很有意义

我错过了什么

更新

这是我在组件中使用它的方式(可能是范围问题?)


您的
getNavigationTab
选择器有一个数组。应该是
getNavigationTab=createSelector(getNavigationRoutes,getNavigationIndex,(routes,index)=>(routes[index])
我很确定,好的,请查看,特别是关于
组合选择器的部分。不管怎么说,我试过不用
[]
,但也没用。嗯,你说得对。我以前从未在“重新选择”中见过这种语法。我再看一眼,看看是否能发现错误如果你在第二个记忆选择器(
getBackNavSupported
)中放了一条log语句,你能验证它在状态更改后是否被调用吗?@Kuf你能找出错误吗?你的
getNavigationTab
选择器有一个数组。应该是
getNavigationTab=createSelector(getNavigationRoutes,getNavigationIndex,(routes,index)=>(routes[index])
我很确定,好的,请查看,特别是关于
组合选择器的部分。不管怎么说,我试过不用
[]
,但也没用。嗯,你说得对。我以前从未在“重新选择”中见过这种语法。我再看一眼,看看是否能发现错误如果你在第二个记忆选择器(
getBackNavSupported
)中放入一条log语句,你能确认它在状态更改后被调用了吗?@Kuf你能找出错误吗?