-
Notifications
You must be signed in to change notification settings - Fork 126
[코드리뷰 요청] 과제2 완료 #170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: ctaaag
Are you sure you want to change the base?
[코드리뷰 요청] 과제2 완료 #170
Changes from 4 commits
493446f
db4b5f3
515cc00
2e8abc6
a4dcfe4
0fd3dea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import React, { useState } from 'react'; | ||
| import Header from './components/Header'; | ||
| import TodoInput from './components/TodoInput'; | ||
| import TodoLists from './components/TodoLists'; | ||
|
|
||
| export default function App() { | ||
| const [inputText, setInputText] = useState(''); | ||
| const [todos, setTodos] = useState([]); | ||
| const randomId = () => Math.random().toString(12).substr(2, 16); | ||
|
||
|
|
||
| const handleSubmit = (e) => { | ||
| e.preventDefault(); | ||
| setTodos([...todos, { id: randomId(), text: inputText }]); | ||
| setInputText(''); | ||
| }; | ||
|
|
||
| const handleChange = (e) => { | ||
| setInputText(e.target.value); | ||
| }; | ||
|
|
||
| const handleClickComplete = (e) => { | ||
| setTodos(todos.filter((item) => e.target.id !== item.id)); | ||
| }; | ||
|
|
||
| return ( | ||
| <div> | ||
| <Header /> | ||
| <TodoInput | ||
|
||
| inputText={inputText} | ||
| onSubmit={handleSubmit} | ||
| onChange={handleChange} | ||
| /> | ||
| <TodoLists todos={todos} onClickComplete={handleClickComplete} /> | ||
| </div> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import React from 'react'; | ||
|
|
||
| export default function Header() { | ||
| return <div>TO-DO</div>; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import React from 'react'; | ||
|
|
||
| export default function TodoInput({ inputText, onSubmit, onChange }) { | ||
| return ( | ||
| <form onSubmit={onSubmit}> | ||
| <input type="text" value={inputText} onChange={onChange} /> | ||
| <button type="submit">추가</button> | ||
| </form> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import React from 'react'; | ||
|
|
||
| export default function TodoLists({ todos, onClickComplete }) { | ||
| const showTodos = () => { | ||
| if (todos.length === 0) { | ||
| return <span>할 일이 없어요!</span>; | ||
| } | ||
| return todos.map((item) => ( | ||
| <li key={item.id}> | ||
| <span>{item.text}</span> | ||
| <button type="button" id={item.id} onClick={onClickComplete}> | ||
| 완료 | ||
| </button> | ||
| </li> | ||
| )); | ||
| }; | ||
|
||
|
|
||
| return <ol>{showTodos()}</ol>; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import React from 'react'; | ||
| import ReactDOM from 'react-dom'; | ||
| import App from './App'; | ||
|
|
||
| ReactDOM.render(<App />, document.getElementById('app')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input이라는 이름이 붙은 이유가
<input />태그로 쓰이거나 혹은 사용자의 입력으로 사용되는 텍스트라서 그런 것 같네요. 만약 이러한 텍스트가 LocalStorage나 외부 API를 통해서 값이 변경될 수 있다면 그때는 이름을 변경해야겠네요