从一个 class 获取数据以使其成为 stackNavigator 选项卡的标题?

Getting data from one class to make it the title of stackNavigator tab?

import { createStackNavigator } from "react-navigation";
import React, { Component } from "react";

class Navigator extends React.Component {
  render() {
    const TitleNameParam = navigation.getParam('TitleNameParam');
    var TitleNameString = JSON.stringify(TitleNameParam);
    var TitleNameObject = JSON.parse(TitleNameString);
  }


}


const AppNavigator = createStackNavigator({
  Launching: {
    screen: LaunchingScreen,
    navigationOptions: {
      title: "Launching Soon",
      headerTitleAllowFontScaling: true,
      headerBackTitle: "Back"
    }
  },

  InfoScreen: {
    screen: InfoScreen,
    navigationOptions: {
      title: Navigator.TitleNameParam,
    }
  }
});



export default AppNavigator;

所以我想做的是从一个 class 获取数据(来自 API)到堆栈导航器 class 这样我就可以将标题替换为任何数据是。我现在拥有的是 class 导航器获取数据(来自 TitleNameParam ),将数据变成一个字符串,导航器试图在 InfoScreen 选项卡中获取它,但没有显示任何内容。

在 InfoScreen 组件上使用导航选项:

class InfoScreen extends React.Component {
  // Set the navigation options for `react-navigation`
  static navigationOptions = ({navigation}) => {
    return {
      headerTitle: navigation.getParam('TitleNameParam');
    }
  }
…
}

当您导航到此路线时使用:

this.props.navigation.navigate('InfoScreen', {TitleNameParam: yourComputedTitleName})

请告诉我这是否正确。