-
Notifications
You must be signed in to change notification settings - Fork 35
3week #75
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: 3week
Are you sure you want to change the base?
3week #75
Conversation
|
|
||
| export default class Game extends Component { | ||
|
|
||
| constructor(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.
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') |
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.
q, key, maxResult값은 언제든 변경할수 있는 값입니다.
따로 변수로 빼서 관리하는 것이 추후 변경이 있을때 변경하기 쉽고 찾기가 쉽습니다.
그리고
문자열과 변수를 혼용해야 할때
Template literals이라는 문법을 사용해서 사용가능합니다.
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Template_literals
|
|
||
| this.setState({// 가공한 데이터로 지금 바로 실행할 데이터와, 목록에 보여줄 데이터를 state에 저장 | ||
| contents:list.slice(1,list.length),//slice 함수는 배열형 데이터를 첫번째인자부터 두번째인자 전까지를 반환해주는 함수 입니다. | ||
| fullContent:list[0]//가져온 데이터중 첫번째 데이터를 화면에서 실행 시킵니다. |
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.
fullContent는 사용하지 않으므로 삭제해주시면 좋습니다!
3주차 과제 제출합니다.