📜  每次访问屏幕时反应原生加载功能 - Javascript代码示例

📅  最后修改于: 2022-03-11 15:03:48.210000             🧑  作者: Mango

代码示例1
You have to add focus listener so when you go back, It will refresh the data 
like

import * as React from 'react';
import { View } from 'react-native';

function AppScreen({ navigation }) {
  React.useEffect(() => {
    const unsubscribe = navigation.addListener('focus', () => {
      // The screen is focused
      // Call any action and update data
    });

    // Return the function to unsubscribe from the event so it gets removed on unmount
    return unsubscribe;
  }, [navigation]);

  return ;
}
source : https://reactnavigation.org/docs/function-after-focusing-screen/