File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 1
1
import React , { useRef } from "react" ;
2
2
import PropTypes from "prop-types" ;
3
3
import clsx from "clsx" ;
4
+ import useComputation from "../../utils/useComputation" ;
4
5
import {
5
6
getDateISO ,
6
7
getFormattedDate ,
@@ -27,6 +28,7 @@ const HvCalendarCell = ({
27
28
...others
28
29
} ) => {
29
30
const buttonEl = useRef ( null ) ;
31
+ const [ title , computeTitle ] = useComputation ( ( ) => getFormattedDate ( value , locale ) ) ;
30
32
const { startDate, endDate } = calendarValue ;
31
33
const isCellToday = isSameDay ( value , today ) ;
32
34
const isCellSelected = isSameDay ( calendarValue , value ) ;
@@ -81,7 +83,8 @@ const HvCalendarCell = ({
81
83
< HvTooltip
82
84
key = { getDateISO ( value ) }
83
85
enterDelay = { 600 }
84
- title = { < HvTypography noWrap > { getFormattedDate ( value , locale ) } </ HvTypography > }
86
+ onOpen = { computeTitle }
87
+ title = { title ? < HvTypography noWrap > { title } </ HvTypography > : "" }
85
88
>
86
89
< div
87
90
className = { clsx ( classes . dateWrapper , {
Original file line number Diff line number Diff line change
1
+ import { useState , useRef } from "react" ;
2
+
3
+ export default function useComputation ( valueFn , valueFallback ) {
4
+ const computed = useRef ( null ) ;
5
+ const [ value , setValue ] = useState ( valueFallback ) ;
6
+
7
+ const computeValue = ( ) => {
8
+ if ( ! computed . current ) {
9
+ setValue ( valueFn ?. ( ) ) ;
10
+ computed . current = true ;
11
+ }
12
+ } ;
13
+
14
+ return [ value , computeValue ] ;
15
+ }
You can’t perform that action at this time.
0 commit comments