Skip to content

Commit

Permalink
Fix Reminders example
Browse files Browse the repository at this point in the history
  • Loading branch information
Marek Fořt committed Mar 18, 2022
1 parent a882f72 commit 1d803e0
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions fixture/src/Reminders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ const ReminderCell = ({
// We delete the element after 1s
// like the reminders app does on iOS
setTimeout(() => {
onCompleted(item);
setChecked(false);
onCompleted(item);
}, 1000);
}, [checked, item]);
}, [checked, item, onCompleted]);

return (
<Animated.View
Expand Down Expand Up @@ -121,37 +121,43 @@ const Reminders = () => {
]);
};

const updateTitle = (id: string, title: string) => {
const newReminders = [...reminders];
const elem = newReminders.find((reminder) => reminder.id === id);
if (elem !== undefined) {
elem.title = title;
}
setReminders(newReminders);
};
const updateTitle = useCallback(
(id: string, title: string) => {
const newReminders = [...reminders];
const elem = newReminders.find((reminder) => reminder.id === id);
if (elem !== undefined) {
elem.title = title;
}
setReminders(newReminders);
},
[setReminders, reminders]
);

const removeItem = (reminder: Reminder) => {
setReminders(
reminders.filter(({ title }) => {
return title !== reminder.title;
})
);
};
const removeItem = useCallback(
(reminder: Reminder) => {
setReminders(
reminders.filter(({ title }) => {
return title !== reminder.title;
})
);
},
[setReminders, reminders]
);

const list = useRef<FlashList<Reminder> | null>(null);

const onChangeText = useCallback(
(item: Reminder, text: string) => {
updateTitle(item.id, text);
},
[reminders]
[updateTitle]
);

const onCompleted = useCallback(
(item: Reminder) => {
removeItem(item);
},
[reminders]
[removeItem]
);

const animateToBottomIfNewItemAdded = (item: Reminder) => {
Expand Down

0 comments on commit 1d803e0

Please sign in to comment.