Skip to content

Instantly share code, notes, and snippets.

@thanhlmm
Last active December 12, 2021 11:52
Show Gist options
  • Save thanhlmm/4dd3e0546568001a5e915cfc3ce95818 to your computer and use it in GitHub Desktop.
Save thanhlmm/4dd3e0546568001a5e915cfc3ce95818 to your computer and use it in GitHub Desktop.
Frontend ELT
const TodoList = () => {
// Extract
const [todos, setTodos] = useState([]); // Todos loaded from backend
const [status, setStatus] = useState('Done');
const [keyword, setKeyWord] = useState('');
const [priority, setPriority] = useState('Important');
// Extract flow 1
const filteredTodos = useMemo(() => {
return todos.filter(item => {
if (status) {
return item.status === status
}
return true;
}).filter(item => {
if (keyword) {
return item.name.includes(item)
}
return true;
});
}, [todos, state, keyword]);
// Extract flow 2
const fitlertedTodosWithPriority = useMemo(() => {
return filteredTodos.filter((item) => {
if (priority) {
return item.priority === priority
}
return true;
});
}, [priority, filteredTodos]):
return // Render your list here with filteredTodos and fitlertedTodosWithPriority
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment