Skip to content

Conversation

@cnnnnh
Copy link

@cnnnnh cnnnnh commented Jan 1, 2020

3주차 과제 제출합니다.


export default class Game extends Component {

constructor(props) {

Choose a reason for hiding this comment

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

state를 사용하기 위한 방법으로 constructor에서 사용할수도 있지만

class property initializers를 이용해서 좀더 간단하게 state를 선언 하실수도 있습니다!
https://react.christmas/2017/17

ex) state = { fullcontent: {}, contents: []}

//유튜브에 ajax 통신을 해서 데이터를 불러 오는 함수
fetchYoutube = () => {
//axios를 이용해서 유튜브에 영상 목록을 달라고 요청
axios.get('https://www.googleapis.com/youtube/v3/search?q=게임&part=snippet&chart=mostPopular&key=AIzaSyASlUxKp9-sRxTnJUghY0f9D0ia0Iqp91U&maxResults=30')

Choose a reason for hiding this comment

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

q, key, maxResult값은 언제든 변경할수 있는 값입니다.
따로 변수로 빼서 관리하는 것이 추후 변경이 있을때 변경하기 쉽고 찾기가 쉽습니다.

그리고

문자열과 변수를 혼용해야 할때

Template literals이라는 문법을 사용해서 사용가능합니다.
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Template_literals

ex) https://www.googleapis.com/youtube/v3/videos?part=snippet&chart=mostPopular&videoCategoryId=${categoryIdOfGaming}&key=${token}&maxResults=${maxResultSize}


this.setState({// 가공한 데이터로 지금 바로 실행할 데이터와, 목록에 보여줄 데이터를 state에 저장
contents:list.slice(1,list.length),//slice 함수는 배열형 데이터를 첫번째인자부터 두번째인자 전까지를 반환해주는 함수 입니다.
fullContent:list[0]//가져온 데이터중 첫번째 데이터를 화면에서 실행 시킵니다.

Choose a reason for hiding this comment

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

fullContent는 사용하지 않으므로 삭제해주시면 좋습니다!

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.

2 participants