Reactjs screenProps.object在navigationOptions中始终返回null

Reactjs screenProps.object在navigationOptions中始终返回null,reactjs,react-native,react-redux,react-navigation,Reactjs,React Native,React Redux,React Navigation,我想把从获取的道具中提取的一部分数据(用户名)放在导航标题上。请查看我的导航选项 static navigationOptions = ({navigation, screenProps}) => ({ ... title: !_.isNil(screenProps.outfitDetail) ? `${screenProps.outfitDetail.user.username}'s Post`: '' }); 我的问题是,title总是返回一个空白字

我想把从获取的道具中提取的一部分数据(用户名)放在导航标题上。请查看我的
导航选项

  static navigationOptions = ({navigation, screenProps}) => ({
    ...
    title: !_.isNil(screenProps.outfitDetail) ? 
    `${screenProps.outfitDetail.user.username}'s Post`: ''
  });
我的问题是,
title
总是返回一个空白字符串,因为
screenProps.oughtDetail
总是空的。我做错了什么?为什么它总是返回空值

我在
componentWillMount()

我可以从
render()函数
获得细节道具

render () {
    const detail = this.props.outfitDetail;
    if(detail) {
      return (
        <ScrollView style={styles.root}>
        ...
在用户配置文件上执行相同的操作

console.log(this.props.currentUser.username); <- prints username
this.props.navigation.navigate('Profile', {username:this.props.currentUser.username});

console.log(this.props.currentUser.username) 您无法使用
screenProps
访问屏幕的组件属性。要在
navigationOptions
中使用Redux存储中的值,您可以在此线程中看到解决方案:

解决方案1:

static navigationOptions = {
  headerTitle: <SomeTitle />
};
像这样使用它

static navigationOptions = ({ navigation }) => ({
  ... 
  title: globalState.path.to.your.data
});

你在哪里传递
屏幕道具
?您在哪里设置
oughtDetail
?如果看不到更多的代码,很难判断。@Scott谢谢你的提问。我想我可以把
screenProps
放到当前屏幕的道具上。我应该把它放在什么地方吗?对于第二个问题,我在mapStateToProps上设置了详细信息。所以我可以从render()函数中获取对象。这很难调试,因为我无法在导航选项上传递console.log()(是由Redux容器注入的
OutfightDetail
FetchOutfightDetail
吗?@Freez是的。我认为屏幕道具没有连接到屏幕的道具上。所以我想我必须在组件上放置道具。感谢你的友好回答,并提供了很多细节。但我在调用组件时会传递额外的道具。我想你的ap方法可行,但我选择的是简单的方法。注意:尽管如此,请给出您的答案。感谢您的输入。非常感谢我认为您可以解决此问题(+200赏金):
static navigationOptions = {
  headerTitle: <SomeTitle />
};
<MainNavigator 
  navigation={addNavigationHelpers({ 
    dispatch, 
    state: state.nav, 
    globalState: state 
  })}
/>
static navigationOptions = ({ navigation }) => ({
  ... 
  title: globalState.path.to.your.data
});