Creating a timer in
componentDidMount, and recycle it in
componentWillUnmount.
For react hooks, creating a timer in useEffect function with
[]as the useEffect check condition which means this hook only runs on first render, and we can recycle the timer in useEffect callback function.



