11import XDate from 'xdate' ;
22import values from 'lodash/values' ;
33import PropTypes from 'prop-types' ;
4- import React , { Fragment , useCallback , useRef } from 'react' ;
4+ import React , { Fragment , useCallback , useRef , useMemo } from 'react' ;
55import { TouchableOpacity , Text , View , ViewProps } from 'react-native' ;
66
77import { xdateToData } from '../../../interface' ;
@@ -52,7 +52,6 @@ const BasicDay = (props: BasicDayProps) => {
5252 testID
5353 } = props ;
5454 const style = useRef ( styleConstructor ( theme ) ) ;
55- const dateData = useRef ( date ? xdateToData ( new XDate ( date ) ) : undefined ) ;
5655 const _marking = marking || { } ;
5756 const isSelected = _marking . selected || state === 'selected' ;
5857 const isDisabled = typeof _marking . disabled !== 'undefined' ? _marking . disabled : state === 'disabled' ;
@@ -61,6 +60,9 @@ const BasicDay = (props: BasicDayProps) => {
6160 const isMultiDot = markingType === Marking . markings . MULTI_DOT ;
6261 const isMultiPeriod = markingType === Marking . markings . MULTI_PERIOD ;
6362 const isCustom = markingType === Marking . markings . CUSTOM ;
63+ const dateData = useMemo ( ( ) => {
64+ return date ? xdateToData ( new XDate ( date ) ) : undefined ;
65+ } , [ date ] ) ;
6466
6567 const shouldDisableTouchEvent = ( ) => {
6668 const { disableTouchEvent} = _marking ;
@@ -126,12 +128,12 @@ const BasicDay = (props: BasicDayProps) => {
126128 } ;
127129
128130 const _onPress = useCallback ( ( ) => {
129- onPress ?.( dateData . current ) ;
130- } , [ onPress ] ) ;
131+ onPress ?.( dateData ) ;
132+ } , [ onPress , date ] ) ;
131133
132134 const _onLongPress = useCallback ( ( ) => {
133- onLongPress ?.( dateData . current ) ;
134- } , [ onLongPress ] ) ;
135+ onLongPress ?.( dateData ) ;
136+ } , [ onLongPress , date ] ) ;
135137
136138 const renderMarking = ( ) => {
137139 const { marked, dotColor, dots, periods} = _marking ;
0 commit comments