-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
85 lines (76 loc) · 1.81 KB
/
index.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import React, { useState } from "react";
import ReactDOM from "react-dom";
import "./index.css";
/*const AddTask = (addTask) => {
const [value, updateValue] = useState("");
};
const handleSubmit= e=>{
e.preventDefault();
if (value !== ""){
AddTask(value)
updateValue("");
}
}
return (
<form onSubmit={handleSubmit}>
<input
type="text"
value={value}
placeholder="enter your task"
onChange={ e => updateValue(e.target.value)}
/>
<button type="submit"><i class='meterial-icons'>add</i></button>
</form>
)
*/
const ToDoList = () => {
const addTask = (text) => updateValue([...tasks, { text }]);
const [tasks, updateValue] = useState([
{
text: "wakeup",
isCompleted: false,
},
{
text: "freshup",
isCompleted: false,
},
{
text: "boostup",
isCompleted: false,
},
]);
const toggletask = (index) => {
const newtask = [...tasks];
if (newtask[index].isCompleted) {
newtask[index].isCompleted = false;
} else {
newtask[index].isCompleted = true;
updateValue(newtask);
}
};
const reomveTask = (index) => {
const newtask = [...tasks];
newtask.splice(index, 1);
updateValue(newtask);
};
return (
<div className="lists-of-tasks-todo">
{tasks.map((task, index) => (
<div className="task-status">
<span
onClick={() => toggletask(index)}
className={
task.isCompleted ? "task-name completed-task" : "task-name"
}
>
{task.text}
</span>
<button onClick={() => reomveTask(index)}>
<i class="meterial-icons">delete</i>
</button>
</div>
))}
</div>
);
};
ReactDOM.render(<ToDoList />, document.getElementById("root"));