使用useSelector将选择器值添加到react钩子中

时间:2020-05-10 19:05:23

标签: reactjs redux react-redux

我习惯于在可能的情况下使用类组件

const mapStateToProps = (state) => {
  return {
    isMobile: isMobile(state)
  }
}

并从此选择器中获取isMobile的值

const width = state => state.ui.screenWidth

export const isMobile = createSelector(
  width,
  (screenWidth) => {
    return screenWidth <= 810
  }
)

使用useSelector时我无法获取值

const { isMobile } = useSelector(state => ({    
    isMobile: state.isMobile
}));

未定义

const { isMobile } = useSelector(state => ({    
    isMobile: isMobile(state)
}));

isMobile不起作用

我如何获得价值?谢谢

0 个答案:

没有答案