Local Storage III - hook

Medium
8
1
29.0% Acceptance

You need to create a custom hook called useTodoList that can be used to manage a todo list stored in local storage.
The hook should return an object with the following properties:

  • todos: an array of todo items, each of which should have the properties id, text, and completed.
  • addTodo: a function that can be used to add a new todo item to the list.
  • removeTodo: a function that can be used to remove a todo item from the list by its id.
  • toggleTodo: a function that can be used to toggle the completion status of a todo item by its id.
    Every time the todo list is updated (e.g., a todo item is added, removed, or completed), the hook should update the corresponding value in local storage.
    We have already written some starting code for you.

Instructions

  • You do not need to edit the App component. Tests will be scoring only the useTodoList hook.

Example test cases

{ todos: array<{ id: number, text: string, completed: boolean }>, addTodo: function, removeTodo: function, toggleTodo: function }

Hints

  • Start by using the useState hook to manage the state of the todo list.
  • Use the useEffect hook to store the updated todo list in local storage whenever it changes.
  • Create three functions: addTodo, removeTodo, and toggleTodo to manipulate the todo list state.