From ec5d1faaa177d8b6622da3802deee1d95606a807 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Tue, 26 Nov 2019 22:28:04 +0200 Subject: [PATCH] TaskList: convert to a pure functional component. --- src/components/TaskList.tsx | 50 +++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/src/components/TaskList.tsx b/src/components/TaskList.tsx index c8c29ef..ab66133 100644 --- a/src/components/TaskList.tsx +++ b/src/components/TaskList.tsx @@ -26,34 +26,30 @@ const sortSelector = createSelector( (entries) => entries.sort((a, b) => a.title.localeCompare(b.title)) ); -class TaskList extends React.PureComponent { - public props: { - entries: TaskType[]; - onItemClick: (entry: TaskType) => void; - }; - - public render() { - const entries = this.props.entries.filter((x) => !x.finished); - const sortedEntries = sortSelector(entries); - - const itemList = sortedEntries.map((entry) => { - const uid = entry.uid; - - return ( - - ); - }); +interface PropsType { + entries: TaskType[]; + onItemClick: (entry: TaskType) => void; +} + +export default React.memo(function TaskList(props: PropsType) { + const entries = props.entries.filter((x) => !x.finished); + const sortedEntries = sortSelector(entries); + + const itemList = sortedEntries.map((entry) => { + const uid = entry.uid; return ( - - {itemList} - + ); - } -} + }); -export default TaskList; + return ( + + {itemList} + + ); +});