Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

yurim22
Copy link

@yurim22 yurim22 commented Apr 5, 2020

Gitstar Ranking

React 환경에서 구현하였습니다.

실행방법

npm install
npm start

아쉬운점

  • react-async 패키지 활용해서 api 요청 상태 관리하는 것 혹은 custom hook 만들어서 도전
  • 각 repository별 star 수를 아이콘과 함께 오른쪽에 배치하고 싶은데 왜 안될까요...

Copy link
Member

@lallaheeee lallaheeee left a 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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.preventDefault() 해주신 있을까요?! 궁금합니다 !

Copy link
Member

@joi0104 joi0104 Apr 16, 2020

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와 같이 이벤트 수식어를 지원해주고 있는데요. 혹시 리액트에는 없을까요?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joi0104

네 !! 거기다 리액트는 return false를 해도 e.preventDefalut가 되지 않아요!! ㅎㅎ
https://ko.reactjs.org/docs/handling-events.html

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오오 신기하네요 ㅎㅎ

to {
transform: rotate(360deg);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 파일은 없어도 될거같아요! ㅎㅎ

Comment on lines +13 to +16
const StarImg = styled.div`
margin-left: 2rem;
margin-right: 1rem;
`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const StarImg = styled.div`
margin-left: 2rem;
margin-right: 1rem;
`;
const StarImg = styled.div`
margin-left: auto;
`;

Copy link

@mango906 mango906 Apr 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

각 repository별 star 수를 아이콘과 함께 오른쪽에 배치하는건 이렇게 하면 될듯 합니다!

(아이콘과 스타 수를 div로 한번 더 묶으면 더 좋을거 같아요)

스크린샷 2020-04-14 오후 9 50 40

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

호오,, 대박! 진짜 감사합니당👍👍

Comment on lines +5 to +12
const Container = styled.div`
border: 1px solid;
display: flex;
flex-direction: row;
width: 70%;
padding: 1rem;
margin-bottom: -2px;
`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

border들이 겹치면서 2px로 나오는 경우가 있는데 이렇게 수정하면 좋을듯 합니다!

Suggested change
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;
}
`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

스크린샷 2020-04-14 오후 9 51 40

스크린샷 2020-04-14 오후 9 54 27

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(사진으론 잘 안보이네요)

Copy link
Author

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`);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 분해할당 가능할 것 같습니다!

Suggested change
const response = await axios.get(`${gitURL}/${userName}/repos`);
const { data } = await axios.get(`${gitURL}/${userName}/repos`);

Comment on lines +52 to +64
<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>

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

Comment on lines +36 to +38
const getUserInfo = async () => {
const response = await axios.get(`${gitURL}/${userName}/repos`);
const { data } = response;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API로직을 관리하는 별도의 파일로 분리하는 것은 어떤가요??
component 파일은 최대한 view 관련 로직만 다루는 것이 좋다고 생각해요! 유지보수할 때도 좋을것 같고요!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

폴더 구조 설계하는것도 더 공부를 해봐야 될 것 같아요😢 너무 어렵...
좋은 의견 감사합니다! 참고해서 수정해볼게욥😉

Comment on lines +20 to +29
<>
<Container>
<div>{name}</div>
<StarImg>
<img src={star} alt="star_image" width="20px" />
</StarImg>

<div>{stargazers_count}</div>
</Container>
</>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Container가 상위에서 하위 컴포넌트들을 감싸고 있기 때문에 Fragment를 사용하지 않아도 될 것 같아요!

Comment on lines +10 to +21
return (
<div>
{repos.map(repo => (
<RepoDetail
key={repo.id}
name={repo.name}
stargazers_count={repo.stargazers_count}
/>
))}
</div>
);
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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}/>);
};

이렇게는 안될까요??

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오옹!! 훨씬 더 보기 간편하네요ㅎㅎ return을 항상 저런식으로 하다보니까 똑같이 맞췄던것 같아요... 감사합니다👍

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

props가 2개 이상이 되거나 안에 내용이 길어져서 한 눈에 보이지 않는다면 줄 바꿈이 있는게 가독성이 더 높지 않을까요??

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 Yuni-Q님 말씀처럼 여러개의 props가 있고 내용이 길어져, 줄바꿈 하는 것이 좀 더 가독성이 높지 않을까 생각했습니다.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

소소한 tip이라면 아래와 같이 구조분해 해서 사용할 수 도있을 것 같아요

Suggested change
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>
);
};

Comment on lines +31 to +34
const getUserName = e => {
e.preventDefault();
setUserName(e.target.value);
};
Copy link

@danivelop danivelop Apr 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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에도 새로운 함수가 할당되고 이를 속성으로 넘겨준 모든컴포넌트가 불필요하게 리렌더링 될 수 있을거같습니다

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

처음에 useCallback 함수 활용해서 구현하려고 했는데 그땐 두번째 인자에 대한 이해가 부족해서 그냥 넘겼었네요ㅠㅜ 그래도 이렇게 짚어주신김에 더 찾아보니까 조금은 알게된 것 같아요😊 효율성을 위해 적절하게 사용하도록 하겠습니다!

Comment on lines +4 to +5
const RepoDetailList = props => {
const { repos } = props;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const RepoDetailList = props => {
const { repos } = props;
const RepoDetailList = ({ repos }) => {

로 줄일수 있을거 같습니다!

Copy link

@eastroots92 eastroots92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전체적으로 비즈니스 로직과, 뷰, 스타일 등이 구분이 되면 좋겠다는 생각이 들었습니다.

하나의 관점을 가지고 폴더 구조와 파일구조를 나누면 어떨까 생각됩니다.
직접 해보시는 것을 매우 추천드리나 만약 너무 막막하다면 구글에 리액트 폴더구조, 디렉토리 구조 등등을 검색해보시면 좋을 것 같아요.

Comment on lines +10 to +21
return (
<div>
{repos.map(repo => (
<RepoDetail
key={repo.id}
name={repo.name}
stargazers_count={repo.stargazers_count}
/>
))}
</div>
);
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 Yuni-Q님 말씀처럼 여러개의 props가 있고 내용이 길어져, 줄바꿈 하는 것이 좀 더 가독성이 높지 않을까 생각했습니다.

Comment on lines +10 to +21
return (
<div>
{repos.map(repo => (
<RepoDetail
key={repo.id}
name={repo.name}
stargazers_count={repo.stargazers_count}
/>
))}
</div>
);
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

소소한 tip이라면 아래와 같이 구조분해 해서 사용할 수 도있을 것 같아요

Suggested change
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",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testing-library는 devDependencies로 분리하는게 좋아보여요!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants