Reputation: 73
I would like to create a method that monitors the current time using momentjs and will execute this.setState()
in a specific time, in react native.
I had no problems getting the current time, the problem is, that i need some kind of a method that will constantly run in the background and execute the task.
Something like angular's $scope.watch
for you guys that are familiar with angular.
Upvotes: 2
Views: 83
Reputation: 6803
use setInterval
componentDidMount() {
let intervalId = setInterval(() => {
this.setTime({
time: //moment time
}
});
}
Upvotes: 0
Reputation: 12882
You can run an interval after the component is mounted:
componentDidMount() {
const interval = setInterval(() => {
//your logic here
this.setState({})
}, 300)
}
Upvotes: 2