我无法在我的项目中创建此共享组件。这是其代码的简化版本:
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.log
或alert
在我的内部添加时,我mapStateToProps
什么也没得到,似乎我无法从我的SharedView
. 我知道我可以将其重写为 class SharedView extends Component { ...
,但由于某些原因,我需要保留格式。
任何想法如何获得这个全局状态值?