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

206
Visualizações
Executing a function on timer end, or refresh timer on input, for an onChange function

I'm in the process of setting up an input filter for a text box, which would execute a specific function that would refresh a display, based on state value of the input box.

I've been confused between setTimeout and setInterval and how to actually implement this, as it needs to do a couple of things:

  1. Timer needs to start on key press (or in this case, onChange event called, with the function name)
  2. If timer hits a specific value (say 2000 for 2 seconds), it terminates and executes the another function.
  3. The timer should refresh if the onchange event is fired again (a new character is input triggering the onChange again).
  4. It's part of a class component.

I'm having a hard time finding anything relevant to what I am trying to do, and what I got with setInterval so far, had been a looping timer that doesn't trigger an out.

Snippet of relevant code and comments:

    handleTextFilterInput = (event) => {
        /** Track input change **/
        const target = event.target;
        const fieldName = target.name;
        const value = target.value;

        let newFilterValues = {...this.state.filterValue};
        newFilterValues[fieldName] = value;

        this.setState({
            filterValue: newFilterValues,
        });


        /**
         * initialize setInterval()/setTimeout() 
         * 
         * Check if timer is active. If it is, refresh it
         * 
         * When the timer reaches value, do this.functionHere once.
         *
         **/
    };
about 4 years ago · Juan Pablo Isaza
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