P
P
pablo_2282020-07-16 18:01:07
React Native
pablo_228, 2020-07-16 18:01:07

How to make a timer in React Native?

Hello!
I tried to make a timer through setInterval and this.setState , but with this approach, the entire application stopped and behaved somehow inappropriately.
Here is an excerpt of my NOT working code:

timer() {
    let timer = setInterval(() => {
      this.setState({
        seconds: this.state.seconds + 1
      })
    }, 1000)
  }

render() {
return(
{this.timer()}
<Text>{this.state.seconds}</Text>
)}


Tell me how to make a timer correctly

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Alexandrovich, 2020-07-16
@pablo_228

https://nabendu.blog/posts/simple-timer-app-with-r...
this is not a bad example , I
just chewed it up a lot
, take a look here https://stackoverflow.com/questions/31963803/creat...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question