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

198
Views
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 answers
Answer question

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 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!