@@ -9,12 +9,13 @@ interface Props {
99
1010export const TEN_MINUTES = 600
1111
12- export const CircleTimer : React . FC < Props > = ( { expiration, timeExpired } ) => {
12+ export const CircleTimer : React . FC < Props > = props => {
13+ const { expiration, timeExpired } = props
1314 const componentMounted = useRef ( true )
1415 const timeoutId = useRef < ReturnType < typeof setTimeout > | null > ( null )
1516 const isFocused = useIsFocused ( )
1617
17- const timerTick = ( ) => {
18+ const timerTick = ( ) : void => {
1819 if ( ! componentMounted . current || ! isFocused ) {
1920 if ( timeoutId . current != null ) {
2021 clearTimeout ( timeoutId . current )
@@ -24,7 +25,7 @@ export const CircleTimer: React.FC<Props> = ({ expiration, timeExpired }) => {
2425 const now = new Date ( )
2526 const nowMilli = now . getTime ( )
2627 const expMil = expiration . getTime ( )
27- if ( expiration && nowMilli >= expMil ) {
28+ if ( nowMilli >= expMil ) {
2829 timeExpired ( )
2930 return
3031 }
@@ -50,18 +51,12 @@ export const CircleTimer: React.FC<Props> = ({ expiration, timeExpired }) => {
5051 } , [ ] )
5152
5253 useEffect ( ( ) => {
53- if ( expiration !== null ) {
54- if ( timeoutId . current != null ) {
55- clearTimeout ( timeoutId . current )
56- }
57- timeoutId . current = setTimeout ( timerTick , 1000 )
54+ if ( timeoutId . current != null ) {
55+ clearTimeout ( timeoutId . current )
5856 }
57+ timeoutId . current = setTimeout ( timerTick , 1000 )
5958 // eslint-disable-next-line react-hooks/exhaustive-deps
60- } , [ expiration ] )
61-
62- if ( ! expiration ) {
63- return null
64- }
59+ } , [ ] )
6560
6661 return < View style = { { width : 1 , height : 1 } } />
6762}
0 commit comments