-
Notifications
You must be signed in to change notification settings - Fork 12
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
7회차 과제 - 구준혁 #5
base: master
Are you sure you want to change the base?
7회차 과제 - 구준혁 #5
Changes from all commits
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 |
---|---|---|
|
@@ -21,3 +21,8 @@ | |
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
/public | ||
package-lock.json | ||
package.json | ||
README.md |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,33 @@ | ||
import React from 'react' | ||
import styled from 'styled-components' | ||
import TodoListItem from './TodoListItem' | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import TodoListItem from './TodoListItem'; | ||
|
||
const TodoList = ({todoList, handleDelete}) => { | ||
const TodoList = ({ todoList, handleDelete, handleComplete }) => { | ||
return ( | ||
<Box> | ||
<h1>할 일 목록</h1> | ||
{todoList.map((el) => { | ||
return <TodoListItem handleDelete={handleDelete} key={el.id} id={el.id} body={el.body}></TodoListItem> | ||
return ( | ||
<TodoListItem | ||
handleDelete={handleDelete} | ||
handleComplete={handleComplete} | ||
key={el.id} | ||
id={el.id} | ||
body={el.body} | ||
complete={el.complete} | ||
></TodoListItem> | ||
); | ||
})} | ||
</Box> | ||
) | ||
} | ||
); | ||
}; | ||
|
||
const Box = styled.div` | ||
margin-top: 50px; | ||
background: #eeeeee; | ||
padding: 50px 20px; | ||
box-sizing: border-box; | ||
border-radius: 15px; | ||
`; | ||
|
||
` | ||
|
||
export default TodoList | ||
export default TodoList; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,29 @@ | ||
import React from 'react' | ||
import styled from 'styled-components' | ||
|
||
const TodoListItem = ({id, body, handleDelete}) => { | ||
|
||
|
||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
const TodoListItem = ({ id, body, complete, handleDelete, handleComplete }) => { | ||
return ( | ||
<Box> | ||
<p>{body}</p> | ||
<button onClick={() => {handleDelete(id)}}>삭제</button> | ||
{complete === false ? <p>{body}</p> : <IsCompleted>{body}</IsCompleted>} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. app.js/ const handleComplete = (id) => {....} 이 함수안 에서도 이 부분이 있는거같은데 코드가 중복으로 쓰이는거 아닌가요 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. app.js의 해당 코드는 complete값을 바꿔주는 코드입니다! |
||
<ButtonBox> | ||
<button | ||
onClick={() => { | ||
handleDelete(id); | ||
}} | ||
> | ||
삭제 | ||
</button> | ||
<button | ||
onClick={() => { | ||
handleComplete(id); | ||
}} | ||
> | ||
완료 | ||
</button> | ||
</ButtonBox> | ||
</Box> | ||
) | ||
} | ||
); | ||
}; | ||
|
||
const Box = styled.div` | ||
background-color: white; | ||
|
@@ -22,6 +34,15 @@ const Box = styled.div` | |
border-radius: 5px; | ||
display: flex; | ||
justify-content: space-between; | ||
` | ||
`; | ||
const ButtonBox = styled.div` | ||
display: flex; | ||
gap: 10px; | ||
`; | ||
|
||
const IsCompleted = styled.p` | ||
color: gray; | ||
text-decoration: line-through; | ||
`; | ||
|
||
export default TodoListItem | ||
export default TodoListItem; |
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.
토글 상태를 true->false , false -> true로 바뀌면서 완료했던 버튼이 다시 되돌아오는 것이군요!!
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.
맞습니다 !! 다만 연산자 활용을 좀 더 잘 했다면 코드를 더 줄일 수 있겠다는 생각이 듭니다!