1

I want to track the time when a user navigates through the screen and when it leaves the screen. I also want to set state and then send those data to API.

const Stack = createStackNavigator();
const Tab = createMaterialTopTabNavigator();
export default function BootcampWeeksScreen(props){
    const { navigation } = props;
const pathway_id=navigation.getParam('pathway_id');
  return (


    <NavigationContainer>
      <Tab.Navigator tabBarOptions={{ scrollEnabled: true }}>
      <Tab.Screen name="Course" component={Courses} initialParams={{pathway_id:pathway_id}} />
        <Tab.Screen name="Roadmap" component={Roadmap} />
      </Tab.Navigator>
    </NavigationContainer>
  );
}

When a user navigates to the Course screen I want to track that time when the user leaves the screen.

How can I do this?

Harsh Mishra
  • 862
  • 3
  • 15
  • 29

1 Answers1

-1

you can do it by storing the time in global variable that is accessible throughout the components. you can use react context or redux for that.

when the user navigates to other page you could probably use

useEffect(()=>{

return ()=>{
  //  when the user navigated to another page this gets execute
  // setting of new date will be from here
 }
},[])
abhi patil
  • 504
  • 2
  • 11