useTodoList Hook
In this lesson, we create the hook to get the ToDo list.
We'll cover the following
useTodoList #
This hook is to simply return the ToDo list.
// ./hooks/useTodoList.js
import { useTrackedState } from '../store';
export const useTodoList = () => {
const state = useTrackedState();
return state.todos;
};
One might think this doesn’t have to be a custom hook, but by hiding the implementation detail, we can refactor this hook easily. For example, we may be able to implement it with useSelector
instead of useTrackedState
.
Next #
In the next lesson, we will learn another hook useAddTodo
.
Get hands-on with 1400+ tech skills courses.