Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

132
Vistas
After wrapping the arrow function, why is the function executed immediately?

I am making an app with react native. If there is no touch response on a current screen, I want to action that automatically advances to the next screen after 5 seconds.

If a button is pressed or input text is entered, I am thinking of clearing setTimeout and counting 5 seconds again. So I wrapped the functions to put in onPress and onChange that I have in screen. However, it works as if the button was pressed. How should I wrap it?... I'd appreciate it if you could let me know.

//ReceiptScreen
...
  componentWillUnmount() {
    this._isMounted = false;
    clearTimeout(this.nextScreenTimer);
  }

handleSendPress = () => {
    if (isValidEmail(this.state.email)) {
      this.props.sendEmailReceipt(this.state.email, this.props.order);
    } else {
      Alert.alert(
        null,
        [
          {
            text: 'close',
            onPress: () => null,
          },
        ],
        {cancelable: true},
      );
    }
  };

handleScreenTimeout = func => {
    console.log('what', func);
    clearTimeout(this.nextScreenTimer);
    this.nextScreenTimer = setTimeout(() => {
      this.handlePressClose();
    }, 5000);
    func();
  };

  componentDidMount() {
    this.nextScreenTimer = setTimeout(() => {
      this.handlePressClose();
    }, 5000);
  }
....

render() {
....
            <InputButton
              placeholder={'example@gmail.com'}
              value={this.state.email}
              onChangeText={text => this.setState({email: text})}
              loading={this.props.isEmailReceiptFetching}
              onPress={this.handleScreenTimeout(this.handleSendPress)}
            />
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to change the following onPress handler

onPress={this.handleScreenTimeout(this.handleSendPress)}

to be a function that calls your function within it as below

onPress={() => this.handleScreenTimeout(this.handleSendPress)}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda