ToDo list
ToDo list
Project Structure
Code
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<div id="root"></div>
<script src="https://unpkg.com/react@17/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@17/umd/react-
dom.development.js"></script>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
</html>
App.js
if (task.trim()) {
setTasks([...tasks, task]);
setTask("");
};
setTasks(updatedTasks);
};
return (
<div className="todo-container">
<div className="input-container">
<input
type="text"
value={task}
/>
<button onClick={addTask}>Add</button>
</div>
<ul className="task-list">
<li key={index}>
{t}
</li>
))}
</ul>
</div>
);
};
style.css
body {
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
.todo-container {
background: #fff;
padding: 20px;
border-radius: 8px;
width: 100%;
max-width: 400px;
text-align: center;
.todo-container h1 {
margin-bottom: 20px;
color: #333;
.input-container {
display: flex;
gap: 10px;
.input-container input {
flex: 1;
padding: 10px;
border-radius: 4px;
.input-container button {
padding: 10px;
background: #007bff;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
.input-container button:hover {
background: #0056b3;
.task-list {
list-style: none;
padding: 0;
margin-top: 20px;
.task-list li {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px;
background: #f9f9f9;
border-radius: 4px;
margin-bottom: 10px;
.task-list button {
background: #ff4d4d;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
.task-list button:hover {
background: #d93636;
}
Result: