Skip to content

Commit 8d3d518

Browse files
committed
Adding missing dependencies to callbacks
1 parent 1ca84dd commit 8d3d518

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/calendar/day/basic/index.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import XDate from 'xdate';
22
import values from 'lodash/values';
33
import PropTypes from 'prop-types';
4-
import React, {Fragment, useCallback, useRef} from 'react';
4+
import React, {Fragment, useCallback, useRef, useMemo} from 'react';
55
import {TouchableOpacity, Text, View, ViewProps} from 'react-native';
66

77
import {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;

src/calendar/header/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ const CalendarHeader = forwardRef((props: CalendarHeaderProps, ref) => {
121121
return onPressArrowLeft(subtractMonth, month);
122122
}
123123
return subtractMonth();
124-
}, [onPressArrowLeft, subtractMonth]);
124+
}, [onPressArrowLeft, subtractMonth, month]);
125125

126126
const onPressRight = useCallback(() => {
127127
if (typeof onPressArrowRight === 'function') {
128128
return onPressArrowRight(addMonth, month);
129129
}
130130
return addMonth();
131-
}, [onPressArrowRight, addMonth]);
131+
}, [onPressArrowRight, addMonth, month]);
132132

133133
const onAccessibilityAction = (event: AccessibilityActionEvent) => {
134134
switch (event.nativeEvent.actionName) {

0 commit comments

Comments
 (0)