@@ -2,6 +2,7 @@ import { isEnabled } from '@automattic/calypso-config';
22import { localizeUrl } from '@automattic/i18n-utils' ;
33import clsx from 'clsx' ;
44import { useTranslate } from 'i18n-calypso' ;
5+ import { useCallback } from 'react' ;
56import { useSelector } from 'react-redux' ;
67import isAtomicSite from 'calypso/state/selectors/is-site-wpcom-atomic' ;
78import { getSiteSlug , isAdminInterfaceWPAdmin , isJetpackSite } from 'calypso/state/sites/selectors' ;
@@ -26,28 +27,31 @@ const StatModuleFollowers = ( { className } ) => {
2627
2728 const { data : subTotals , isLoading, isError : hasError } = useSubscribersTotalsQueries ( siteId ) ;
2829
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 ( ) ;
3335
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 ) ;
3840
39- let result = '' ;
41+ let result = '' ;
4042
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+ }
4850
49- return result ;
50- } ;
51+ return result ;
52+ } ,
53+ [ translate ]
54+ ) ;
5155
5256 const noData = ! subTotals . subscribers . length ;
5357 const summaryPageSlug = siteSlug || '' ;
0 commit comments