Search code examples
react-nativeexponavigation-drawerrefresh

how can I refresh screen that in drawer navigation when focused react native expo


I navigate by drawer to screen with Id and this Id not changed

export default function ScreenPage({ route, navigation }) {
    useFocusEffect(
        React.useCallback(() => {
            Alert.alert(route.params.id);
          return () => {
            Alert.alert(route.params.id);
          };
        }, [])
      );
return (<View/>)
}

The Id not changed all the time till I refresh the source code


Solution

  • I found solution to use

    import { useIsFocused } from "@react-navigation/native"; 
    export default function Details({ route, navigation }) { 
       const isFocused = useIsFocused();
       useEffect(() => {
            fetchDetails()
        }, [isFocused])
    return(<View />)
    }
    

    then all data on the screen will be refresh every time I navigate to screen