Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 在React导航中返回主屏幕时如何调用构造函数?_Reactjs_React Native_React Native Android_React Navigation_React Native Ios - Fatal编程技术网

Reactjs 在React导航中返回主屏幕时如何调用构造函数?

Reactjs 在React导航中返回主屏幕时如何调用构造函数?,reactjs,react-native,react-native-android,react-navigation,react-native-ios,Reactjs,React Native,React Native Android,React Navigation,React Native Ios,我有一个createBottomTabNavigator,其中有一个createStackNavigator: const SettingsStack = createStackNavigator({ SettingsScreen: { screen: SettingsClass, //1st screen }, EditProfile: { screen: EditProfileClass . //2nd screen }, }, 当我从EditProfil

我有一个
createBottomTabNavigator
,其中有一个
createStackNavigator

const SettingsStack = createStackNavigator({
  SettingsScreen: {
    screen: SettingsClass,  //1st screen
  },
  EditProfile: {
    screen: EditProfileClass . //2nd screen
  },
},

当我从EditProfile屏幕移回主SettingsScreen时,我希望再次运行SettingsScreen中的componentWillMount()(每次返回时)。现在它只运行一次。或者在SettingsScreen中创建一个函数,该函数在我从EditProfile屏幕返回到主SettingsScreen时运行。这样,我的主设置屏幕现在将刷新最新的配置文件信息。如何实现这一点?

您可以在
SettingsScreen

class SettingsScreen extends Component {
  componentDidMount() {
    this.focusListener = this.props.navigation.addListener('didFocus', () => {
      // Call your refresh code here
    });
  }

  componentWillUnmount() {
    this.focusListener.remove();
  }
}