File tree Expand file tree Collapse file tree 1 file changed +13
-11
lines changed Expand file tree Collapse file tree 1 file changed +13
-11
lines changed Original file line number Diff line number Diff line change @@ -42,32 +42,34 @@ type State = {
4242
4343export class Timer extends React . Component < Props , State > {
4444 _timeoutId : ?TimeoutID
45+ _intervalId : ?IntervalID
4546
4647 state = {
4748 now : new Date ( ) ,
4849 loading : false ,
4950 }
5051
5152 componentDidMount ( ) {
52- this . queue ( )
53- }
54-
55- componentWillUnmount ( ) {
56- // eslint-disable-next-line no-eq-null
57- this . _timeoutId != null && clearTimeout ( this . _timeoutId )
58- }
59-
60- queue = ( ) => {
6153 // get the time remaining until the next $interval
6254 let { interval } = this . props
6355 let nowMs = this . state . now . getTime ( )
6456 let untilNextInterval = msUntilIntervalRepeat ( nowMs , interval )
6557
66- this . _timeoutId = setTimeout ( this . updateTime , untilNextInterval )
58+ this . _timeoutId = setTimeout ( ( ) => {
59+ this . updateTime ( )
60+ this . _intervalId = setInterval ( this . updateTime , interval )
61+ } , untilNextInterval )
62+ }
63+
64+ componentWillUnmount ( ) {
65+ // eslint-disable-next-line no-eq-null
66+ this . _timeoutId != null && clearTimeout ( this . _timeoutId )
67+ // eslint-disable-next-line no-eq-null
68+ this . _intervalId != null && clearInterval ( this . _intervalId )
6769 }
6870
6971 updateTime = ( ) => {
70- this . setState ( ( ) => ( { now : new Date ( ) } ) , this . queue )
72+ this . setState ( ( ) => ( { now : new Date ( ) } ) )
7173 }
7274
7375 refresh = async ( ) => {
You can’t perform that action at this time.
0 commit comments