Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

170
Visualizações
calling a function only one time outside of useEffect react native

I have a function for setting up push notifications which needs to be called one time after the user logs in. This has to be outside of useEffect because the documentation says so.

I tried calling it in the component which comes after the user logs in, but the function is called 3 times after app is opened from killed state. Is there a way to limit this call to only one?

Here is the code so far:

const HomeScreen: FC<Props> = ({navigation}) => {

  setupPushNotifications();

    return (
    <SafeAreaView style={homeStyles.wrapper}>
      <Header navigation={navigation} />
      <View style={homeStyles.container}>
...
...

One way to do it would have been to use constructor in react classes, but the whole application is written in ES6 and relies too much on hooks.

Is there any other way i can make this work?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can call this in your main file index.js in root directory of your project

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';

setupPushNotifications();

AppRegistry.registerComponent(appName, () => App);

But you said you want to call it only if user is logged in then in the same file where you placed setupPushNotifications just update the position of it and move it out side class block.

setupPushNotifications();

const HomeScreen: FC<Props> = ({navigation}) => {
   ...
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda