0

我无法在我的项目中创建此共享组件。这是其代码的简化版本:

import React from 'react';
import { View } from 'react-native';
import { connect } from 'react-redux';

function mapStateToProps(state) {
  return {
    platform: state.device.get('platform') //defines if iOS or Android
  };
}

export function SharedView({ theme, ...props }) {
  return <View {...props}>{theme}</View>;
}

export default SharedView(
  connect(mapStateToProps, null)
);

当我尝试添加console.logalert在我的内部添加时,我mapStateToProps什么也没得到,似乎我无法从我的SharedView. 我知道我可以将其重写为 class SharedView extends Component { ...,但由于某些原因,我需要保留格式。

任何想法如何获得这个全局状态值?

4

1 回答 1

2

connect是一个高阶函数——你的组件应该被包裹在其中,而不是相反。

export default connect(mapStateToProps)(SharedView);
于 2016-06-15T12:46:15.680 回答