Skip to content

Commit 1ca84dd

Browse files
authored
Merge pull request #1800 from wix/infra/migrate_to_functional_components
Migrate to functional components - 1
2 parents 43c7174 + 154dd11 commit 1ca84dd

File tree

9 files changed

+368
-462
lines changed

9 files changed

+368
-462
lines changed

example/src/screens/calendars.tsx

Lines changed: 15 additions & 11 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
);

0 commit comments

Comments
 (0)