-
Notifications
You must be signed in to change notification settings - Fork 10
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
Github Star Ranking #6
base: master
Are you sure you want to change the base?
Conversation
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.
LGTM👍🏻🤩
코드가 깔끔해서 읽기 좋네유
}); | ||
|
||
const getUserName = e => { | ||
e.preventDefault(); |
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.
e.preventDefault()
해주신 있을까요?! 궁금합니다 !
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.
e.preventDefault() 경우, 사용하는 경우가 많아서 Vue에서는 :click.prevent
와 같이 이벤트 수식어를 지원해주고 있는데요. 혹시 리액트에는 없을까요?
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.
네 !! 거기다 리액트는 return false
를 해도 e.preventDefalut가 되지 않아요!! ㅎㅎ
https://ko.reactjs.org/docs/handling-events.html
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.
오오 신기하네요 ㅎㅎ
to { | ||
transform: rotate(360deg); | ||
} | ||
} |
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.
이 파일은 없어도 될거같아요! ㅎㅎ
const StarImg = styled.div` | ||
margin-left: 2rem; | ||
margin-right: 1rem; | ||
`; |
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.
const StarImg = styled.div` | |
margin-left: 2rem; | |
margin-right: 1rem; | |
`; | |
const StarImg = styled.div` | |
margin-left: auto; | |
`; |
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.
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.
호오,, 대박! 진짜 감사합니당👍👍
const Container = styled.div` | ||
border: 1px solid; | ||
display: flex; | ||
flex-direction: row; | ||
width: 70%; | ||
padding: 1rem; | ||
margin-bottom: -2px; | ||
`; |
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.
border들이 겹치면서 2px로 나오는 경우가 있는데 이렇게 수정하면 좋을듯 합니다!
const Container = styled.div` | |
border: 1px solid; | |
display: flex; | |
flex-direction: row; | |
width: 70%; | |
padding: 1rem; | |
margin-bottom: -2px; | |
`; | |
const Container = styled.div` | |
border: 1px solid; | |
display: flex; | |
flex-direction: row; | |
width: 70%; | |
padding: 1rem; | |
& + div { | |
margin-top: -1px; | |
} | |
`; |
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.
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.
(사진으론 잘 안보이네요)
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.
넹! 말씀하신부분 참고해서 수정했어요~~👍
}; | ||
|
||
const getUserInfo = async () => { | ||
const response = await axios.get(`${gitURL}/${userName}/repos`); |
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.
이렇게 분해할당 가능할 것 같습니다!
const response = await axios.get(`${gitURL}/${userName}/repos`); | |
const { data } = await axios.get(`${gitURL}/${userName}/repos`); |
<div className="App"> | ||
<Container> | ||
<Header inputHandler={getUserName} clickHandler={getUserInfo} /> | ||
<UserName>{userInfo.name}</UserName> | ||
<RepoInfo> | ||
{userInfo.repo} Repositories | {userInfo.star} stars | ||
</RepoInfo> | ||
<hr /> | ||
<div className="list"> | ||
<RepoDetailList repos={repos} /> | ||
</div> | ||
</Container> | ||
</div> |
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.
semantic한 html tag를 사용하는 것도 좋을것 같아요!
전에 좋은 글을 읽어서 공유할게요~
https://medium.com/@soeunlee/%EC%8B%9C%EB%A7%A8%ED%8B%B1%ED%95%98%EA%B2%8C-html%EC%9D%84-%EC%A7%A0%EB%8B%A4%EB%8A%94-%EA%B2%83-90612ffc988e
const getUserInfo = async () => { | ||
const response = await axios.get(`${gitURL}/${userName}/repos`); | ||
const { data } = response; |
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.
API로직을 관리하는 별도의 파일로 분리하는 것은 어떤가요??
component 파일은 최대한 view 관련 로직만 다루는 것이 좋다고 생각해요! 유지보수할 때도 좋을것 같고요!
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.
폴더 구조 설계하는것도 더 공부를 해봐야 될 것 같아요😢 너무 어렵...
좋은 의견 감사합니다! 참고해서 수정해볼게욥😉
<> | ||
<Container> | ||
<div>{name}</div> | ||
<StarImg> | ||
<img src={star} alt="star_image" width="20px" /> | ||
</StarImg> | ||
|
||
<div>{stargazers_count}</div> | ||
</Container> | ||
</> |
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.
Container
가 상위에서 하위 컴포넌트들을 감싸고 있기 때문에 Fragment를 사용하지 않아도 될 것 같아요!
return ( | ||
<div> | ||
{repos.map(repo => ( | ||
<RepoDetail | ||
key={repo.id} | ||
name={repo.name} | ||
stargazers_count={repo.stargazers_count} | ||
/> | ||
))} | ||
</div> | ||
); | ||
}; |
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.
return ( | |
<div> | |
{repos.map(repo => ( | |
<RepoDetail | |
key={repo.id} | |
name={repo.name} | |
stargazers_count={repo.stargazers_count} | |
/> | |
))} | |
</div> | |
); | |
}; | |
return repos.map(repo => <RepoDetail key={repo.id} name={repo.name} stargazers_count={repo.stargazers_count}/>); | |
}; |
이렇게는 안될까요??
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.
오옹!! 훨씬 더 보기 간편하네요ㅎㅎ return을 항상 저런식으로 하다보니까 똑같이 맞췄던것 같아요... 감사합니다👍
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.
props가 2개 이상이 되거나 안에 내용이 길어져서 한 눈에 보이지 않는다면 줄 바꿈이 있는게 가독성이 더 높지 않을까요??
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.
저도 Yuni-Q님 말씀처럼 여러개의 props가 있고 내용이 길어져, 줄바꿈 하는 것이 좀 더 가독성이 높지 않을까 생각했습니다.
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.
소소한 tip이라면 아래와 같이 구조분해 해서 사용할 수 도있을 것 같아요
return ( | |
<div> | |
{repos.map(repo => ( | |
<RepoDetail | |
key={repo.id} | |
name={repo.name} | |
stargazers_count={repo.stargazers_count} | |
/> | |
))} | |
</div> | |
); | |
}; | |
return ( | |
<div> | |
{repos.map(({id, name, stargazers_count}) => ( | |
<RepoDetail | |
key={id} | |
name={name} | |
stargazers_count={stargazers_count} | |
/> | |
))} | |
</div> | |
); | |
}; |
const getUserName = e => { | ||
e.preventDefault(); | ||
setUserName(e.target.value); | ||
}; |
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.
const getUserName = e => { | |
e.preventDefault(); | |
setUserName(e.target.value); | |
}; | |
const getUserName = useCallback(e => { | |
e.preventDefault(); | |
setUserName(e.target.value); | |
}, []); |
getUserName에 함수를 할당할 때 useCallback
이나 lodash의 memoize
을 사용해 메모이제이션을 해주는게 좋을거 같아요! 메모이제이션을 해주지 않으면 username을 입력할 때마다 App
컴포넌트는 리렌더링 되는데 그때마다 getUserName
에도 새로운 함수가 할당되고 이를 속성으로 넘겨준 모든컴포넌트가 불필요하게 리렌더링 될 수 있을거같습니다
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.
처음에 useCallback
함수 활용해서 구현하려고 했는데 그땐 두번째 인자에 대한 이해가 부족해서 그냥 넘겼었네요ㅠㅜ 그래도 이렇게 짚어주신김에 더 찾아보니까 조금은 알게된 것 같아요😊 효율성을 위해 적절하게 사용하도록 하겠습니다!
const RepoDetailList = props => { | ||
const { repos } = props; |
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.
const RepoDetailList = props => { | |
const { repos } = props; | |
const RepoDetailList = ({ repos }) => { |
로 줄일수 있을거 같습니다!
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.
전체적으로 비즈니스 로직과, 뷰, 스타일 등이 구분이 되면 좋겠다는 생각이 들었습니다.
하나의 관점을 가지고 폴더 구조와 파일구조를 나누면 어떨까 생각됩니다.
직접 해보시는 것을 매우 추천드리나 만약 너무 막막하다면 구글에 리액트 폴더구조, 디렉토리 구조 등등을 검색해보시면 좋을 것 같아요.
return ( | ||
<div> | ||
{repos.map(repo => ( | ||
<RepoDetail | ||
key={repo.id} | ||
name={repo.name} | ||
stargazers_count={repo.stargazers_count} | ||
/> | ||
))} | ||
</div> | ||
); | ||
}; |
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.
저도 Yuni-Q님 말씀처럼 여러개의 props가 있고 내용이 길어져, 줄바꿈 하는 것이 좀 더 가독성이 높지 않을까 생각했습니다.
return ( | ||
<div> | ||
{repos.map(repo => ( | ||
<RepoDetail | ||
key={repo.id} | ||
name={repo.name} | ||
stargazers_count={repo.stargazers_count} | ||
/> | ||
))} | ||
</div> | ||
); | ||
}; |
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.
소소한 tip이라면 아래와 같이 구조분해 해서 사용할 수 도있을 것 같아요
return ( | |
<div> | |
{repos.map(repo => ( | |
<RepoDetail | |
key={repo.id} | |
name={repo.name} | |
stargazers_count={repo.stargazers_count} | |
/> | |
))} | |
</div> | |
); | |
}; | |
return ( | |
<div> | |
{repos.map(({id, name, stargazers_count}) => ( | |
<RepoDetail | |
key={id} | |
name={name} | |
stargazers_count={stargazers_count} | |
/> | |
))} | |
</div> | |
); | |
}; |
"dependencies": { | ||
"@testing-library/jest-dom": "^4.2.4", | ||
"@testing-library/react": "^9.3.2", | ||
"@testing-library/user-event": "^7.1.2", |
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.
testing-library는 devDependencies로 분리하는게 좋아보여요!
Gitstar Ranking
React 환경에서 구현하였습니다.
실행방법
npm install
npm start
아쉬운점