The ToDoList
component is a simple React-based to-do list application. It allows users to add tasks, delete tasks, and reorder tasks within the list. The component demonstrates basic state management using React hooks and includes functionality for user interaction through buttons and input fields.
- Add Task: Users can add a new task to the list by entering text into an input field and clicking the "Add" button.
- Delete Task: Users can remove a task from the list by clicking the "Delete" button next to the task.
- Move Task Up: Users can move a task up in the list by clicking the "๐" button next to the task.
- Move Task Down: Users can move a task down in the list by clicking the "๐" button next to the task.
tasks
: An array of tasks (strings) initialized with two default tasks: "eat breakfast" and "take a shower".newTask
: A string representing the new task input by the user.
handleInputChange(event)
: Updates thenewTask
state with the value entered by the user in the input field.addTask()
: Adds the new task to thetasks
array if the input is not empty and clears the input field.deleteTask(index)
: Removes the task at the specified index from thetasks
array.moveTaskUp(index)
: Moves the task at the specified index one position up in thetasks
array.moveTaskDown(index)
: Moves the task at the specified index one position down in thetasks
array.
- The main component wrapper is a
<div>
with the class name "to-do-list". - The title of the application is displayed in an
<h1>
tag. - An input field for adding new tasks is paired with an "Add" button.
- The list of tasks is rendered as an ordered list (
<ol>
), with each task being a list item (<li>
) containing:- The task text.
- A "Delete" button to remove the task.
- An "๐" button to move the task up.
- An "๐" button to move the task down.
- Add a Task: Type a task into the input field and click the "Add" button. The task will be added to the bottom of the list.
- Delete a Task: Click the "Delete" button next to a task to remove it from the list.
- Move a Task Up: Click the "๐" button next to a task to move it one position up in the list.
- Move a Task Down: Click the "๐" button next to a task to move it one position down in the list.