Answers for "let timer = setInterval(() => { setDate(new Date().toLocaleString()), 1000; }); return () => clearInterval(timer);"

1

react function being called every minute

componentDidMount() {
  this.interval = setInterval(() => this.setState({ time: Date.now() }), 1000);
}
componentWillUnmount() {
  clearInterval(this.interval);
}
Posted by: Guest on May-25-2020

Code answers related to "let timer = setInterval(() => { setDate(new Date().toLocaleString()), 1000; }); return () => clearInterval(timer);"

Code answers related to "Javascript"

Browse Popular Code Answers by Language