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

200
Vistas
How do I toggle states after every timeout?

I'm working on injecting words from an array into an element using setTimeout. I'm also using Baffle.js to add an obfuscation transition to said word change.

The flow should be something like:

word 1 -> obfuscate over 3s -> word 2... and so on.

My code is below:

render() {

        return (
            <div className='landing-page-wrapper'>
                <div className="main-text">
                    <span>AMIDST </span>
                    <Baffle
                        characters={'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz~!@#$%^&*()-+=[]{}|;:,./<>?'}
                        exclude={[' ']}
                        speed={50}
                        revealDuration={0}
                        obfuscate={this.state.obfuscate}>
                        {this.state.targetWord}
                    </Baffle>
                </div>
            </div>
        );
    }


    toggleObfuscate() {
        this.setState({ obfuscate: !this.state.obfuscate })
    }

    injectWords() {
        const wordslist = [
            'creativity', 'emotion', 'logic', 'change', 'positivity', 'direction', 'thought', 'humanity'
        ]

        wordslist.forEach((words, index) => {
            setTimeout(() => {
                this.setState({targetWord: words})
            }, (index+1) * 3000)
        })
    }

I've managed to inject the words over 3 seconds, however, I can't seem to get the obfuscation part down. Can anyone help me here?

Thanks in advance

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Update 15.03.2022

I managed to fix this issue by adding a setTimeout to the toggleObfuscate() function. This basically resets the state value for obfuscate

The fix looks something like this:

toggleObfuscate() {
        this.setState({ obfuscate: !this.state.obfuscate })

        setTimeout(() => {
            this.setState({obfuscate: false})
        }, 1000)
    }

    injectWords() {
        const wordslist = [
            'creativity', 'emotion', 'logic', 'change', 'positivity', 'direction', 'thought', 'humanity'
        ]

        wordslist.forEach((words, index) => {
            setTimeout(() => {
                this.setState({targetWord: words})
                this.toggleObfuscate();
            }, (index+1) * 3000)
        })
    }
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