Last active
December 12, 2021 11:52
-
-
Save thanhlmm/4dd3e0546568001a5e915cfc3ce95818 to your computer and use it in GitHub Desktop.
Frontend ELT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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