@@ -2,6 +2,7 @@ import { isEnabled } from '@automattic/calypso-config';
2
2
import { localizeUrl } from '@automattic/i18n-utils' ;
3
3
import clsx from 'clsx' ;
4
4
import { useTranslate } from 'i18n-calypso' ;
5
+ import { useCallback } from 'react' ;
5
6
import { useSelector } from 'react-redux' ;
6
7
import isAtomicSite from 'calypso/state/selectors/is-site-wpcom-atomic' ;
7
8
import { getSiteSlug , isAdminInterfaceWPAdmin , isJetpackSite } from 'calypso/state/sites/selectors' ;
@@ -26,28 +27,31 @@ const StatModuleFollowers = ( { className } ) => {
26
27
27
28
const { data : subTotals , isLoading, isError : hasError } = useSubscribersTotalsQueries ( siteId ) ;
28
29
29
- const calculateOffset = ( pastValue ) => {
30
- const now = new Date ( ) ;
31
- const value = new Date ( pastValue ) ;
32
- const difference = now . getTime ( ) - value . getTime ( ) ;
30
+ const calculateOffset = useCallback (
31
+ ( pastValue ) => {
32
+ const now = new Date ( ) ;
33
+ const value = new Date ( pastValue ) ;
34
+ const difference = now . getTime ( ) - value . getTime ( ) ;
33
35
34
- const seconds = Math . floor ( difference / 1000 ) ;
35
- const minutes = Math . ceil ( seconds / 60 ) ;
36
- const hours = Math . floor ( minutes / 60 ) ;
37
- const days = Math . floor ( hours / 24 ) ;
36
+ const seconds = Math . floor ( difference / 1000 ) ;
37
+ const minutes = Math . ceil ( seconds / 60 ) ;
38
+ const hours = Math . floor ( minutes / 60 ) ;
39
+ const days = Math . floor ( hours / 24 ) ;
38
40
39
- let result = '' ;
41
+ let result = '' ;
40
42
41
- if ( days > 0 ) {
42
- result = translate ( '%d days' , { args : days } ) ;
43
- } else if ( hours > 0 ) {
44
- result = translate ( '%d hours' , { args : hours } ) ;
45
- } else if ( minutes > 0 ) {
46
- result = translate ( '%d minutes' , { args : minutes } ) ;
47
- }
43
+ if ( days > 0 ) {
44
+ result = translate ( '%d days' , { args : days } ) ;
45
+ } else if ( hours > 0 ) {
46
+ result = translate ( '%d hours' , { args : hours } ) ;
47
+ } else if ( minutes > 0 ) {
48
+ result = translate ( '%d minutes' , { args : minutes } ) ;
49
+ }
48
50
49
- return result ;
50
- } ;
51
+ return result ;
52
+ } ,
53
+ [ translate ]
54
+ ) ;
51
55
52
56
const noData = ! subTotals . subscribers . length ;
53
57
const summaryPageSlug = siteSlug || '' ;
0 commit comments