forked from laviii123/Btecky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask Tracker App.jsx
38 lines (33 loc) · 883 Bytes
/
Task Tracker App.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import React, { useState } from 'react';
import Task from './Task';
import './TaskTracker.css';
const TaskTracker = () => {
const [tasks, setTasks] = useState([]);
const addTask = (taskText) => {
setTasks([...tasks, { id: Date.now(), text: taskText }]);
};
const deleteTask = (taskId) => {
setTasks(tasks.filter((task) => task.id !== taskId));
};
return (
<div className="task-tracker">
<h1>Task Tracker</h1>
<input
type="text"
placeholder="Add a task..."
onKeyPress={(e) => {
if (e.key === 'Enter') {
addTask(e.target.value);
e.target.value = '';
}
}}
/>
<div className="task-list">
{tasks.map((task) => (
<Task key={task.id} task={task} onDelete={deleteTask} />
))}
</div>
</div>
);
};
export default TaskTracker;