xref: /expo/home/components/NavigationEvents.tsx (revision 09fa69c7)
1import { useNavigation } from '@react-navigation/native';
2import * as React from 'react';
3
4export default function NavigationEvents(props: { children?: any; onDidFocus: () => void }) {
5  const navigation = useNavigation();
6
7  React.useEffect(() => {
8    const unsubscribe = navigation.addListener('focus', () => {
9      // The screen is focused
10      props.onDidFocus();
11    });
12    // Return the function to unsubscribe from the event so it gets removed on unmount
13    return () => {
14      unsubscribe();
15    };
16  }, [navigation]);
17
18  return props.children ?? null;
19}
20