Skip to content

Commit 03c1026

Browse files
committed
Day - move to memo. Improve example
1 parent 8e383a2 commit 03c1026

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

example/src/screens/calendars.tsx

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useState, Fragment, useCallback} from 'react';
1+
import React, {useState, Fragment, useCallback, useMemo} from 'react';
22
import {StyleSheet, View, ScrollView, Text, TouchableOpacity} from 'react-native';
33
import {Calendar, CalendarProps} from 'react-native-calendars';
44
import testIDs from '../testIDs';
@@ -8,9 +8,20 @@ const INITIAL_DATE = '2020-02-02';
88
const CalendarsScreen = () => {
99
const [selected, setSelected] = useState(INITIAL_DATE);
1010

11-
const onDayPress: CalendarProps['onDayPress'] = day => {
11+
const onDayPress: CalendarProps['onDayPress'] = useCallback(day => {
1212
setSelected(day.dateString);
13-
};
13+
}, []);
14+
15+
const marked = useMemo(() => {
16+
return {
17+
[selected]: {
18+
selected: true,
19+
disableTouchEvent: true,
20+
selectedColor: 'orange',
21+
selectedTextColor: 'red'
22+
}
23+
};
24+
}, [selected]);
1425

1526
const renderCalendarWithSelectableDate = () => {
1627
return (
@@ -22,14 +33,7 @@ const CalendarsScreen = () => {
2233
current={INITIAL_DATE}
2334
style={styles.calendar}
2435
onDayPress={onDayPress}
25-
markedDates={{
26-
[selected]: {
27-
selected: true,
28-
disableTouchEvent: true,
29-
selectedColor: 'orange',
30-
selectedTextColor: 'red'
31-
}
32-
}}
36+
markedDates={marked}
3337
/>
3438
</Fragment>
3539
);
@@ -454,7 +458,7 @@ const CalendarsScreen = () => {
454458
return (
455459
<Fragment>
456460
{renderCalendarWithSelectableDate()}
457-
{renderCalendarWithWeekNumbers()}
461+
{/* {renderCalendarWithWeekNumbers()}
458462
{renderCalendarWithMinAndMaxDates()}
459463
{renderCalendarWithCustomDay()}
460464
{renderCalendarWithInactiveDays()}
@@ -465,7 +469,7 @@ const CalendarsScreen = () => {
465469
{renderCalendarWithPeriodMarkingAndSpinner()}
466470
{renderCalendarWithPeriodMarkingAndDotMarking()}
467471
{renderCalendarWithMultiPeriodMarking()}
468-
{renderCalendarWithCustomMarkingType()}
472+
{renderCalendarWithCustomMarkingType()} */}
469473
</Fragment>
470474
);
471475
};

src/calendar/day/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const Day = (props: DayProps) => {
7070
);
7171
};
7272

73-
export default Day;
73+
export default React.memo<DayProps>(props => <Day {...props}/>);
7474
Day.displayName = 'Day';
7575
Day.propTypes = {
7676
...BasicDay.propTypes,

0 commit comments

Comments
 (0)