Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
Ejecute la misma función en cada pantalla para todas las pantallas cuando se enfocan con React Navigation

¿Cómo puedo ejecutar la misma función en cada pantalla con React Navigation? Estoy usando React Native y TypeScript. Tengo una navegación con home , profile , etc...

Tengo la siguiente función y quiero que se ejecute cuando navegues a profile , home , etc.

 const getFunction = (): void => { console.log("execute function"); };

Probé el siguiente código pero no funciona:

 useEffect(() => { const listener = navigation.addListener("focus", (e) => { getFunction(); }); return () => listener; }, [navigation]);

Una descripción general de mis pantallas:

 return ( ... <Stack.Screen name='home' component={home} /> <Stack.Screen name='profile' component={profile} /> ... )

por favor si me pudieras ayudar te lo agradeceria mucho!! :)

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede usar screenListeners prop en el navegador. De esta forma, puede especificar oyentes para eventos de todas las pantallas. Como ejemplo así:

 <Stack.Navigator screenListeners={{ focus: (e) => { // code you wanna execute goes here console.log("Focus has changed") }, }} > <Stack.Screen name="home" component={home} /> <Stack.Screen name="profile" component={profile} /> </Stack.Navigator>
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!