1
1
import DateManager from "@/utilities/DateManager" ;
2
2
import classNames from "classnames" ;
3
3
import { useRouter } from "next/router" ;
4
- import React , { useMemo } from "react" ;
4
+ import React , { useCallback , useMemo } from "react" ;
5
5
6
6
interface DurationBadgeProps {
7
7
value : number ;
@@ -10,22 +10,21 @@ interface DurationBadgeProps {
10
10
11
11
export default function DurationBadge ( { value, type = "gray" } : DurationBadgeProps ) {
12
12
const router = useRouter ( ) ;
13
+ const getDuration = useCallback ( ( value : number , locale : string ) => {
14
+ if ( ! value ) return 0 ;
15
+ return DateManager . humanize ( value , locale ) ;
16
+ } , [ ] ) ;
13
17
const duration = useMemo ( ( ) => {
14
- return ( value : number ) => {
15
- if ( ! value ) {
16
- return 0 ;
17
- }
18
- return DateManager . humanize ( value , router . locale as string ) ;
19
- } ;
20
- } , [ router . locale ] ) ;
18
+ return getDuration ( value , router . locale as string ) ;
19
+ } , [ router . locale , value , getDuration ] ) ;
21
20
return (
22
21
< div
23
22
className = { classNames ( "text-xxs uppercase font-semibold px-2 rounded-3xl inline-block text-gray-500 text-nowrap" , {
24
23
"bg-gray-200" : type === "gray" ,
25
24
"border border-gray-200" : type === "bordered" ,
26
25
} ) }
27
26
>
28
- { duration ( value ) }
27
+ { duration }
29
28
</ div >
30
29
) ;
31
30
}
0 commit comments