-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.jsx
More file actions
126 lines (118 loc) · 3.1 KB
/
App.jsx
File metadata and controls
126 lines (118 loc) · 3.1 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//eslint-disabled- vite
import { useState } from 'react';
import './App.css';
import AddTodo from './AddTodo';
import List from './List';
let nextId = 3;
const initialTodos = [
{ id: 0, title: 'CJ올리브영 지원서 제출하기', done: true },
{ id: 1, title: 'LG U+ 지원서 작성하기', done: false },
];
export default function App() {
const [todos, setTodos] = useState(initialTodos);
const [isEditing, setIsEditing] = useState(false);
const [profile, setProfile] = useState({
name: "이지수",
major: "정보통신공학과",
email: "leeland21@naver.com ",
github: "jisssu.github",
});
function handleAddTodo(title) {
setTodos(prevTodos => [
...prevTodos,
{ id: nextId++, title: title, done: false }
]);
}
function handleChangeTodo(nextTodo) {
setTodos(prevTodos =>
prevTodos.map(todo =>
todo.id === nextTodo.id ? nextTodo : todo
)
);
}
function handleDeleteTodo(todoId) {
setTodos(prevTodos => prevTodos.filter(todo => todo.id !== todoId));
}
const handleEditProfile = (e) => {
e.preventDefault();
setIsEditing(!isEditing);
};
const handleProfileChange = (e) => {
const { name, value } = e.target;
setProfile(prevProfile => ({
...prevProfile,
[name]: value,
}));
};
return (
<>
<form>
<h2>안녕하세요, 프론트엔드 개발자{' '}
{isEditing ? (
<input
value={profile.name}
onChange={handleProfileChange}
/>
) : (
<>{profile.name}입니다.</>
)}
</h2>
<div className="box">
<label>
📎 전공 : {' '}
{isEditing ? (
<input
type="text"
name="major"
value={profile.major}
onChange={handleProfileChange}
/>
) : (
profile.major
)}
</label>
<label>
📎 이메일 : {' '}
{isEditing ? (
<input
type="email"
name="email"
value={profile.email}
onChange={handleProfileChange}
/>
) : (
profile.email
)}
</label>
<label>
📎 깃허브 : {' '}
{isEditing ? (
<input
type="text"
name="github"
value={profile.github}
onChange={handleProfileChange}
/>
) : (
profile.github
)}
</label>
</div>
<div className="profile-edit">
<button type="button" onClick={handleEditProfile}>
{isEditing ? '저장' : 'Edit Profile'}
</button>
</div>
</form>
<div className="todo">
<h3>오늘의 할일</h3>
<AddTodo onAddTodo={handleAddTodo} />
<List
todos={todos}
onChangeTodo={handleChangeTodo}
onDeleteTodo={handleDeleteTodo}
/>
</div>
</>
);
}