SlideShare a Scribd company logo
1 of 31
Download to read offline
ReactAJAVASCRIPTLIBRARYFORBUILDINGUSERINTERFACES
강의 순서
1회차
개발 환경 구성 – SublimeText3, Node.js 설치 (필요시)
HTML, JS 기초
React 소개
Node.js 간단한 실습
2회차
React 튜토리얼
React 예제 작성
HeXA - 기초부2 ReactJS Tutorial
오늘 할 것들!
리액트 썰기
props, state
React Component Specification
React Component Lifecycle
예제(유배지) 만들기
HeXA - 기초부2 ReactJS Tutorial
코드를 받아오자(업뎃함)
• GIT이 있건 없건!!
https://github.com/kimxogus/React-web-tutorial 들어갑니다.
HeXA - 기초부2 ReactJS Tutorial
코드를 받아오자(업뎃함)
• GIT이 있건 없건!!
https://github.com/kimxogus/React-web-tutorial 들어갑니다.
Star를 누릅니다. (프리미엄 A/S 서비스)
HeXA - 기초부2 ReactJS Tutorial
코드를 받아오자(업뎃함)
• GIT이 있건 없건!!
https://github.com/kimxogus/React-web-tutorial 들어갑니다.
Star를 누릅니다. (프리미엄 A/S 서비스)
Fork를 누릅니다. (다운로드가 빨라집니다. 똑같은 것 같다면 기분탓)
HeXA - 기초부2 ReactJS Tutorial
코드를 받아오자(업뎃함)
• GIT이 있건 없건!!
https://github.com/kimxogus/React-web-tutorial 들어갑니다.
Star를 누릅니다. (프리미엄 A/S 서비스)
Fork를 누릅니다. (다운로드가 빨라집니다. 똑같은 것 같다면 기분탓)
Download ZIP을 클릭하여 zip파일을 다운
압축 풀기!
HeXA - 기초부2 ReactJS Tutorial
props & state
props state
상위 요소에게서 상속
(기본값은 자신이 정할 수 있다.)
스스로 가지고 있는 값, 상태
값이 바뀌면 Component가 업데이트 된다.
(자세한건 Lifecycle 참고)
하위요소로 값을 전달할 수 있다.
(props 형태로 전달)
HeXA - 기초부2 ReactJS Tutorial
React Component Specification
displayName : Component 이름(JSX를 쓴다면 신경X)
mixins : Addon
statics : Static 값 또는 함수
getDefaultProps : props의 기본값
propTypes : props의 타입 정의
getInitialState : state 기본값 정의
render : 렌더링 함수 (필수!)
HeXA - 기초부2 ReactJS Tutorial
백문이 불여일코
HeXA @ UNIST const Content = React.createClass({
render: function() {
return(
<h2>
HeXA @ UNIST
</h2>
);
}
});
ReactDOM.render(
<Content/>,
document.getElementById(“container”)
);
HeXA - 기초부2 ReactJS Tutorial
백문이 불여일코
HeXA @ UNIST const Content = React.createClass({
render: function() {
return(
<h2>
{this.props.name} @ {this.props.school}
</h2>
);
}
});
ReactDOM.render(
<Content name=“HeXA” school=“UNIST”/>,
document.getElementById(“container”)
);
HeXA - 기초부2 ReactJS Tutorial
백문이 불여일코
HeXA @ UNIST const Content = React.createClass({
getDefaultProps: function() {
return {
name: “HeXA”,
school: “UNIST”
};
},
render: function() {
return (
<h2>
{this.props.name} @ {this.props.school}
</h2>
);
}
});
ReactDOM.render(
<Content/>,
document.getElementById(“container”)
);
HeXA - 기초부2 ReactJS Tutorial
백문이 불여일코
HeXA @ UNIST const Content = React.createClass({
getDefaultProps: function() {
return {
name: “HeXA”,
school: “UNIST”
};
},
propTypes: {
name: React.PropTypes.string,
school: React.PropTypes.string
},
render: function() {
return(
<h2>
{this.props.name} @ {this.props.school}
</h2>
);
}
});
HeXA - 기초부2 ReactJS Tutorial
백문이 불여일코
HeXA @ UNIST
0
const Content = React.createClass({
...
getInitialState: function() {
return {
clicks: 0
};
},
render: function() {
return(
<div>
<h2>
{this.props.name} @ {this.props.school}
</h2>
<h4>{this.state.clicks}</h4>
</div>
);
}
});
HeXA - 기초부2 ReactJS Tutorial
백문이 불여일코
HeXA @ UNIST
0
const Content = React.createClass({
...
getInitialState: function() {
return {
clicks: 0
};
},
render: function() {
return(
<div>
<h2>
{this.props.name} @ {this.props.school}
</h2>
<h4>{this.state.clicks}</h4>
<button type=“button” onClick={this.onClick}>
Increase Number
</button>
</div>
);
},
onClick: function() {
this.setState({clicks: this.state.clicks + 1});
}
});
HeXA - 기초부2 ReactJS Tutorial
Increase Number
백문이 불여일코
displayName, mixins, statics은
쓸 일 거의 없으므로 생략
const Content = React.createClass({
getDefaultProps: function() {
return {
name: “Name”,
school: “School”
};
},
propTypes: {
name: React.PropTypes.string,
school: React.PropTypes.string
},
getInitialState: function() {
return {
clicks: 0
};
},
render: function() {
return(
<div>
<h2>
{this.props.name} @ {this.props.school}
</h2>
<h4>{this.state.clicks}</h4>
<button
type=“button” onClick={this.onClick}>
Increase Number
</button>
</div>
);
},
onClick: function() {
this.setState({
clicks: this.state.clicks + 1
});
}
});
HeXA - 기초부2 ReactJS Tutorial
React Lifecycle
• Mounting
componentWillMount
componentDidMount
• Updating
componentWillReceiveProps
shouldComponentUpdate
componentWillUpdate
componentDidUpdate
• Unmounting
componentWillUnmount
HeXA - 기초부2 ReactJS Tutorial
React Lifecycle
• Mounting
componentWillMount : 컴포넌트 생성 전
componentDidMount : 컴포넌트 생성 후
• Updating
componentWillReceiveProps : 새로운 props 받기 전
shouldComponentUpdate : 컴포넌트 업데이트 여부
componentWillUpdate : 컴포넌트 업데이트 전
componentDidUpdate : 컴포넌트 업데이트 후
• Unmounting
componentWillUnmount : 컴포넌트 소멸 전
HeXA - 기초부2 ReactJS Tutorial
React Lifecycle 예시
const Content = React.createClass({
...
componentDidMount: function() {
alert(“Hi”);
},
...
});
HeXA - 기초부2 ReactJS Tutorial
React Lifecycle 예시
const Content = React.createClass({
...
componentDidMount: function() {
alert(“Hi”);
},
componentWillUpdate: function() {
alert(“Updating”);
},
...
});
HeXA - 기초부2 ReactJS Tutorial
React Lifecycle 예시
const Content = React.createClass({
...
componentDidMount: function() {
alert(“Hi”);
},
shouldComponentUpdate: function(newProps, newState) {
if(newProps.school == "UNIST") {
return false;
} else {
return true;
}
},
componentWillUpdate: function() {
alert(“Updating”);
},
...
});
HeXA - 기초부2 ReactJS Tutorial
React 컴파일
• Babel: 적용된 preset에 맞게 문법 변환을 해준다.
• Webpack: 문법 변환 뿐 아니라 라이브러리까지 통합된
하나의 js파일로 만들어주며(bundle) 설정을 통한 Uglify(minify),
Common chunk 등의 optimization도 지원
• Browserify: Webpack같은 js 번들 라이브러리
HeXA - 기초부2 ReactJS Tutorial
준비작업
NPM (Node Package Manager) 를 이용해
라이브러리 다운로드 받기
: npm install
babel, webpack 다운받기(Global Toolkit)
: npm install –g babel-cli webpack
HeXA - 기초부2 ReactJS Tutorial
Babel 컴파일
babel --presets react js/src/babel --out-dir js/out
: --presets react > React 프리셋 적용
: js/src/babel > js/src/babel에 있는 js파일을 컴파일
: --out-dir js/out > 컴파일된 js파일을 js/out로 보냄
--watch 추가하면 파일이 변경될 때 마다 자동으로 컴파일!
package.json의 scripts에 미리 선언 되어있다.
npm run-script babel 입력하면 실행가능
HeXA - 기초부2 ReactJS Tutorial
Babel 컴파일
Code [ src/Content.js ]
const Content = React.createClass({
...
});
ReactDOM.render(
...
);
Usage [React compiled by Babel]
<script src=“react.js”>
<script src=“react-dom.js”>
<script src=“out/Content.js”>
HeXA - 기초부2 ReactJS Tutorial
Webpack 컴파일
webpack.config.js 파일에 설정 후 webpack 커맨드 실행
webpack --progress --colors
: --progress > progress를 터미널에 출력
: --colors > 출력 결과에 색을 입혀 이쁘게 출력
--watch 추가하면 파일 변경시 자동 컴파일
마찬가지로 package.json scripts에 추가되어있음
npm run-script webpack
HeXA - 기초부2 ReactJS Tutorial
Webpack 컴파일
Code [ src/Content.js ]
const React = require(‘react’);
const ReactDOM = require(‘react-dom’);
const Content = React.createClass({
...
});
ReactDOM.render(
...
);
Usage [React compiled by Webpack]
<script src=“out/Content.js”>
HeXA - 기초부2 ReactJS Tutorial
배울건 다 배웠다.
코-딩하자
유배지를 웹으로 구현하자
카테고리 선택
카테고리에 해당하는 배달업소 로드
이름, 전화번호, 위치 보여주기!
js/src/UBaeZi 를 보고 따라해봅시다!
HeXA - 기초부2 ReactJS Tutorial
유니스트 배달 지존
모바일 어플. 만들 수 있습니다.
const React = require(‘react’);
: 웹
const React = require(‘react-native’);
: 어플
HeXA - 기초부2 ReactJS Tutorial
수고하셨습니다
김태현
kgyoo8232@gmail.com
HeXA - 기초부2 ReactJS Tutorial

More Related Content

What's hot

[115] clean fe development_윤지수
[115] clean fe development_윤지수[115] clean fe development_윤지수
[115] clean fe development_윤지수NAVER D2
 
React를 이용하여 멀티플랫폼에서 개발하기
React를 이용하여 멀티플랫폼에서 개발하기React를 이용하여 멀티플랫폼에서 개발하기
React를 이용하여 멀티플랫폼에서 개발하기WebFrameworks
 
[141] react everywhere
[141] react everywhere[141] react everywhere
[141] react everywhereNAVER D2
 
Isomorphicspring Isomorphic - spring web seminar 2015
Isomorphicspring Isomorphic - spring web seminar 2015Isomorphicspring Isomorphic - spring web seminar 2015
Isomorphicspring Isomorphic - spring web seminar 2015sung yong jung
 
React 애플리케이션 아키텍처 - 아무도 알려주지 않아서 혼자서 삽질했다.
React 애플리케이션 아키텍처 - 아무도 알려주지 않아서 혼자서 삽질했다.React 애플리케이션 아키텍처 - 아무도 알려주지 않아서 혼자서 삽질했다.
React 애플리케이션 아키텍처 - 아무도 알려주지 않아서 혼자서 삽질했다.병대 손
 
Clean Front-End Development
Clean Front-End DevelopmentClean Front-End Development
Clean Front-End Development지수 윤
 
Meteor 0.3.6 Preview
Meteor 0.3.6 PreviewMeteor 0.3.6 Preview
Meteor 0.3.6 PreviewJuntai Park
 
Nodejs, PhantomJS, casperJs, YSlow, expressjs
Nodejs, PhantomJS, casperJs, YSlow, expressjsNodejs, PhantomJS, casperJs, YSlow, expressjs
Nodejs, PhantomJS, casperJs, YSlow, expressjs기동 이
 
진짜기초 Node.js
진짜기초 Node.js진짜기초 Node.js
진짜기초 Node.jsWoo Jin Kim
 
다함께, FluxUtils 한바퀴!
다함께, FluxUtils 한바퀴!다함께, FluxUtils 한바퀴!
다함께, FluxUtils 한바퀴!우영 주
 
Front-end Development Process - 어디까지 개선할 수 있나
Front-end Development Process - 어디까지 개선할 수 있나Front-end Development Process - 어디까지 개선할 수 있나
Front-end Development Process - 어디까지 개선할 수 있나JeongHun Byeon
 
20131217 html5
20131217 html520131217 html5
20131217 html5DK Lee
 
Progressive Web Apps
Progressive Web AppsProgressive Web Apps
Progressive Web Appsjungkees
 
overview of spring4
overview of spring4overview of spring4
overview of spring4Arawn Park
 

What's hot (18)

역시 Redux
역시 Redux역시 Redux
역시 Redux
 
[115] clean fe development_윤지수
[115] clean fe development_윤지수[115] clean fe development_윤지수
[115] clean fe development_윤지수
 
React를 이용하여 멀티플랫폼에서 개발하기
React를 이용하여 멀티플랫폼에서 개발하기React를 이용하여 멀티플랫폼에서 개발하기
React를 이용하여 멀티플랫폼에서 개발하기
 
[141] react everywhere
[141] react everywhere[141] react everywhere
[141] react everywhere
 
React Redux React Native
React Redux React NativeReact Redux React Native
React Redux React Native
 
Isomorphicspring Isomorphic - spring web seminar 2015
Isomorphicspring Isomorphic - spring web seminar 2015Isomorphicspring Isomorphic - spring web seminar 2015
Isomorphicspring Isomorphic - spring web seminar 2015
 
Spring Boot 2
Spring Boot 2Spring Boot 2
Spring Boot 2
 
React 애플리케이션 아키텍처 - 아무도 알려주지 않아서 혼자서 삽질했다.
React 애플리케이션 아키텍처 - 아무도 알려주지 않아서 혼자서 삽질했다.React 애플리케이션 아키텍처 - 아무도 알려주지 않아서 혼자서 삽질했다.
React 애플리케이션 아키텍처 - 아무도 알려주지 않아서 혼자서 삽질했다.
 
Clean Front-End Development
Clean Front-End DevelopmentClean Front-End Development
Clean Front-End Development
 
Spring Boot 1
Spring Boot 1Spring Boot 1
Spring Boot 1
 
Meteor 0.3.6 Preview
Meteor 0.3.6 PreviewMeteor 0.3.6 Preview
Meteor 0.3.6 Preview
 
Nodejs, PhantomJS, casperJs, YSlow, expressjs
Nodejs, PhantomJS, casperJs, YSlow, expressjsNodejs, PhantomJS, casperJs, YSlow, expressjs
Nodejs, PhantomJS, casperJs, YSlow, expressjs
 
진짜기초 Node.js
진짜기초 Node.js진짜기초 Node.js
진짜기초 Node.js
 
다함께, FluxUtils 한바퀴!
다함께, FluxUtils 한바퀴!다함께, FluxUtils 한바퀴!
다함께, FluxUtils 한바퀴!
 
Front-end Development Process - 어디까지 개선할 수 있나
Front-end Development Process - 어디까지 개선할 수 있나Front-end Development Process - 어디까지 개선할 수 있나
Front-end Development Process - 어디까지 개선할 수 있나
 
20131217 html5
20131217 html520131217 html5
20131217 html5
 
Progressive Web Apps
Progressive Web AppsProgressive Web Apps
Progressive Web Apps
 
overview of spring4
overview of spring4overview of spring4
overview of spring4
 

Viewers also liked

React 소개 및 구현방법 Demo
React 소개 및 구현방법 DemoReact 소개 및 구현방법 Demo
React 소개 및 구현방법 DemoDaesung Kim
 
jQuery angular, React.js 로 댓글달아보기 공부했던 기록
jQuery angular, React.js 로 댓글달아보기 공부했던 기록jQuery angular, React.js 로 댓글달아보기 공부했던 기록
jQuery angular, React.js 로 댓글달아보기 공부했던 기록라한사 아
 
How_to_choose_the_right_framework
How_to_choose_the_right_frameworkHow_to_choose_the_right_framework
How_to_choose_the_right_frameworkJT Jintae Jung
 
Lars thorup-react-and-redux-2016-09
Lars thorup-react-and-redux-2016-09Lars thorup-react-and-redux-2016-09
Lars thorup-react-and-redux-2016-09BestBrains
 
Breaking the Server-Client Divide with Node.js and React
Breaking the Server-Client Divide with Node.js and ReactBreaking the Server-Client Divide with Node.js and React
Breaking the Server-Client Divide with Node.js and ReactDejan Glozic
 
Nodifying the Enterprise - Prince Soni, TO THE NEW
Nodifying the Enterprise - Prince Soni, TO THE NEWNodifying the Enterprise - Prince Soni, TO THE NEW
Nodifying the Enterprise - Prince Soni, TO THE NEWNodejsFoundation
 
React, Redux and es6/7
React, Redux and es6/7React, Redux and es6/7
React, Redux and es6/7Dongho Cho
 
Front end dev 2016 & beyond
Front end dev 2016 & beyondFront end dev 2016 & beyond
Front end dev 2016 & beyondJae Sung Park
 
[124] 하이브리드 앱 개발기 김한솔
[124] 하이브리드 앱 개발기 김한솔[124] 하이브리드 앱 개발기 김한솔
[124] 하이브리드 앱 개발기 김한솔NAVER D2
 
[125]react로개발자2명이플랫폼4개를서비스하는이야기 심상민
[125]react로개발자2명이플랫폼4개를서비스하는이야기 심상민[125]react로개발자2명이플랫폼4개를서비스하는이야기 심상민
[125]react로개발자2명이플랫폼4개를서비스하는이야기 심상민NAVER D2
 
더 나은 개발자 되기
더 나은 개발자 되기더 나은 개발자 되기
더 나은 개발자 되기JeongHun Byeon
 
React JS and why it's awesome
React JS and why it's awesomeReact JS and why it's awesome
React JS and why it's awesomeAndrew Hull
 
Le festival de cannes 2016 - histoire de l'affiche
Le festival de cannes 2016 - histoire de l'afficheLe festival de cannes 2016 - histoire de l'affiche
Le festival de cannes 2016 - histoire de l'afficheChristian Giordano
 
Deview 2015 review
Deview 2015 reviewDeview 2015 review
Deview 2015 review석규 오
 

Viewers also liked (17)

React 소개 및 구현방법 Demo
React 소개 및 구현방법 DemoReact 소개 및 구현방법 Demo
React 소개 및 구현방법 Demo
 
jQuery angular, React.js 로 댓글달아보기 공부했던 기록
jQuery angular, React.js 로 댓글달아보기 공부했던 기록jQuery angular, React.js 로 댓글달아보기 공부했던 기록
jQuery angular, React.js 로 댓글달아보기 공부했던 기록
 
Flux 예제 분석 2
Flux 예제 분석 2Flux 예제 분석 2
Flux 예제 분석 2
 
How_to_choose_the_right_framework
How_to_choose_the_right_frameworkHow_to_choose_the_right_framework
How_to_choose_the_right_framework
 
Lars thorup-react-and-redux-2016-09
Lars thorup-react-and-redux-2016-09Lars thorup-react-and-redux-2016-09
Lars thorup-react-and-redux-2016-09
 
Breaking the Server-Client Divide with Node.js and React
Breaking the Server-Client Divide with Node.js and ReactBreaking the Server-Client Divide with Node.js and React
Breaking the Server-Client Divide with Node.js and React
 
Nodifying the Enterprise - Prince Soni, TO THE NEW
Nodifying the Enterprise - Prince Soni, TO THE NEWNodifying the Enterprise - Prince Soni, TO THE NEW
Nodifying the Enterprise - Prince Soni, TO THE NEW
 
React, Redux and es6/7
React, Redux and es6/7React, Redux and es6/7
React, Redux and es6/7
 
Front end dev 2016 & beyond
Front end dev 2016 & beyondFront end dev 2016 & beyond
Front end dev 2016 & beyond
 
[124] 하이브리드 앱 개발기 김한솔
[124] 하이브리드 앱 개발기 김한솔[124] 하이브리드 앱 개발기 김한솔
[124] 하이브리드 앱 개발기 김한솔
 
[125]react로개발자2명이플랫폼4개를서비스하는이야기 심상민
[125]react로개발자2명이플랫폼4개를서비스하는이야기 심상민[125]react로개발자2명이플랫폼4개를서비스하는이야기 심상민
[125]react로개발자2명이플랫폼4개를서비스하는이야기 심상민
 
더 나은 개발자 되기
더 나은 개발자 되기더 나은 개발자 되기
더 나은 개발자 되기
 
React js
React jsReact js
React js
 
React JS and why it's awesome
React JS and why it's awesomeReact JS and why it's awesome
React JS and why it's awesome
 
Le festival de cannes 2016 - histoire de l'affiche
Le festival de cannes 2016 - histoire de l'afficheLe festival de cannes 2016 - histoire de l'affiche
Le festival de cannes 2016 - histoire de l'affiche
 
sungmin slide
sungmin slidesungmin slide
sungmin slide
 
Deview 2015 review
Deview 2015 reviewDeview 2015 review
Deview 2015 review
 

Similar to React 튜토리얼 2차시

Spring Boot + React + Gradle in VSCode
Spring Boot + React + Gradle in VSCodeSpring Boot + React + Gradle in VSCode
Spring Boot + React + Gradle in VSCodedpTablo
 
[TECHCON 2019: MOBILE - Android]2.예제에서는 알려주지 않는 Model 이야기
[TECHCON 2019: MOBILE - Android]2.예제에서는 알려주지 않는 Model 이야기[TECHCON 2019: MOBILE - Android]2.예제에서는 알려주지 않는 Model 이야기
[TECHCON 2019: MOBILE - Android]2.예제에서는 알려주지 않는 Model 이야기NAVER Engineering
 
3.component 101
3.component 1013.component 101
3.component 101Daniel Lim
 
JSP 프로그래밍 #02 서블릿과 JSP 시작하기
JSP 프로그래밍 #02 서블릿과 JSP 시작하기JSP 프로그래밍 #02 서블릿과 JSP 시작하기
JSP 프로그래밍 #02 서블릿과 JSP 시작하기Myungjin Lee
 
Django를 Django답게, Django로 뉴스 사이트 만들기
Django를 Django답게, Django로 뉴스 사이트 만들기Django를 Django답게, Django로 뉴스 사이트 만들기
Django를 Django답게, Django로 뉴스 사이트 만들기Kyoung Up Jung
 
Node.js and react
Node.js and reactNode.js and react
Node.js and reactHyungKuIm
 
Netty 세미나
Netty 세미나Netty 세미나
Netty 세미나Jang Hoon
 
React Hooks 마법. 그리고 깔끔한 사용기
React Hooks 마법. 그리고 깔끔한 사용기React Hooks 마법. 그리고 깔끔한 사용기
React Hooks 마법. 그리고 깔끔한 사용기NAVER SHOPPING
 
바닐라에서 React까지
바닐라에서 React까지바닐라에서 React까지
바닐라에서 React까지Wonjun Hwang
 
(IT실무교육/국비지원교육/자바/스프링교육추천)#15.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)
(IT실무교육/국비지원교육/자바/스프링교육추천)#15.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)(IT실무교육/국비지원교육/자바/스프링교육추천)#15.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)
(IT실무교육/국비지원교육/자바/스프링교육추천)#15.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)탑크리에듀(구로디지털단지역3번출구 2분거리)
 
레일스를 이용한 애자일 웹 개발 가이드
레일스를 이용한 애자일 웹 개발 가이드레일스를 이용한 애자일 웹 개발 가이드
레일스를 이용한 애자일 웹 개발 가이드Sukjoon Kim
 

Similar to React 튜토리얼 2차시 (20)

Spring Boot + React + Gradle in VSCode
Spring Boot + React + Gradle in VSCodeSpring Boot + React + Gradle in VSCode
Spring Boot + React + Gradle in VSCode
 
[TECHCON 2019: MOBILE - Android]2.예제에서는 알려주지 않는 Model 이야기
[TECHCON 2019: MOBILE - Android]2.예제에서는 알려주지 않는 Model 이야기[TECHCON 2019: MOBILE - Android]2.예제에서는 알려주지 않는 Model 이야기
[TECHCON 2019: MOBILE - Android]2.예제에서는 알려주지 않는 Model 이야기
 
React Everywhere
React EverywhereReact Everywhere
React Everywhere
 
3.component 101
3.component 1013.component 101
3.component 101
 
[Codelab 2017] ReactJS 기초
[Codelab 2017] ReactJS 기초[Codelab 2017] ReactJS 기초
[Codelab 2017] ReactJS 기초
 
(리액트기초강좌)Reactjs helloworld_리액트공부열심히하세요~
(리액트기초강좌)Reactjs helloworld_리액트공부열심히하세요~(리액트기초강좌)Reactjs helloworld_리액트공부열심히하세요~
(리액트기초강좌)Reactjs helloworld_리액트공부열심히하세요~
 
REACTJS HelloWorld
REACTJS HelloWorldREACTJS HelloWorld
REACTJS HelloWorld
 
JSP 프로그래밍 #02 서블릿과 JSP 시작하기
JSP 프로그래밍 #02 서블릿과 JSP 시작하기JSP 프로그래밍 #02 서블릿과 JSP 시작하기
JSP 프로그래밍 #02 서블릿과 JSP 시작하기
 
Django를 Django답게, Django로 뉴스 사이트 만들기
Django를 Django답게, Django로 뉴스 사이트 만들기Django를 Django답게, Django로 뉴스 사이트 만들기
Django를 Django답게, Django로 뉴스 사이트 만들기
 
Springmvc
SpringmvcSpringmvc
Springmvc
 
Node.js and react
Node.js and reactNode.js and react
Node.js and react
 
4-3. jquery
4-3. jquery4-3. jquery
4-3. jquery
 
Netty 세미나
Netty 세미나Netty 세미나
Netty 세미나
 
React Hooks 마법. 그리고 깔끔한 사용기
React Hooks 마법. 그리고 깔끔한 사용기React Hooks 마법. 그리고 깔끔한 사용기
React Hooks 마법. 그리고 깔끔한 사용기
 
바닐라에서 React까지
바닐라에서 React까지바닐라에서 React까지
바닐라에서 React까지
 
요즘웹개발
요즘웹개발요즘웹개발
요즘웹개발
 
(Spring Data JPA)게시판 리스트보기_오라클, 스프링부트,페이지나누기
(Spring Data JPA)게시판 리스트보기_오라클, 스프링부트,페이지나누기(Spring Data JPA)게시판 리스트보기_오라클, 스프링부트,페이지나누기
(Spring Data JPA)게시판 리스트보기_오라클, 스프링부트,페이지나누기
 
Webpack&babel
Webpack&babelWebpack&babel
Webpack&babel
 
(IT실무교육/국비지원교육/자바/스프링교육추천)#15.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)
(IT실무교육/국비지원교육/자바/스프링교육추천)#15.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)(IT실무교육/국비지원교육/자바/스프링교육추천)#15.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)
(IT실무교육/국비지원교육/자바/스프링교육추천)#15.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)
 
레일스를 이용한 애자일 웹 개발 가이드
레일스를 이용한 애자일 웹 개발 가이드레일스를 이용한 애자일 웹 개발 가이드
레일스를 이용한 애자일 웹 개발 가이드
 

React 튜토리얼 2차시

  • 2. 강의 순서 1회차 개발 환경 구성 – SublimeText3, Node.js 설치 (필요시) HTML, JS 기초 React 소개 Node.js 간단한 실습 2회차 React 튜토리얼 React 예제 작성 HeXA - 기초부2 ReactJS Tutorial
  • 3. 오늘 할 것들! 리액트 썰기 props, state React Component Specification React Component Lifecycle 예제(유배지) 만들기 HeXA - 기초부2 ReactJS Tutorial
  • 4. 코드를 받아오자(업뎃함) • GIT이 있건 없건!! https://github.com/kimxogus/React-web-tutorial 들어갑니다. HeXA - 기초부2 ReactJS Tutorial
  • 5. 코드를 받아오자(업뎃함) • GIT이 있건 없건!! https://github.com/kimxogus/React-web-tutorial 들어갑니다. Star를 누릅니다. (프리미엄 A/S 서비스) HeXA - 기초부2 ReactJS Tutorial
  • 6. 코드를 받아오자(업뎃함) • GIT이 있건 없건!! https://github.com/kimxogus/React-web-tutorial 들어갑니다. Star를 누릅니다. (프리미엄 A/S 서비스) Fork를 누릅니다. (다운로드가 빨라집니다. 똑같은 것 같다면 기분탓) HeXA - 기초부2 ReactJS Tutorial
  • 7. 코드를 받아오자(업뎃함) • GIT이 있건 없건!! https://github.com/kimxogus/React-web-tutorial 들어갑니다. Star를 누릅니다. (프리미엄 A/S 서비스) Fork를 누릅니다. (다운로드가 빨라집니다. 똑같은 것 같다면 기분탓) Download ZIP을 클릭하여 zip파일을 다운 압축 풀기! HeXA - 기초부2 ReactJS Tutorial
  • 8. props & state props state 상위 요소에게서 상속 (기본값은 자신이 정할 수 있다.) 스스로 가지고 있는 값, 상태 값이 바뀌면 Component가 업데이트 된다. (자세한건 Lifecycle 참고) 하위요소로 값을 전달할 수 있다. (props 형태로 전달) HeXA - 기초부2 ReactJS Tutorial
  • 9. React Component Specification displayName : Component 이름(JSX를 쓴다면 신경X) mixins : Addon statics : Static 값 또는 함수 getDefaultProps : props의 기본값 propTypes : props의 타입 정의 getInitialState : state 기본값 정의 render : 렌더링 함수 (필수!) HeXA - 기초부2 ReactJS Tutorial
  • 10. 백문이 불여일코 HeXA @ UNIST const Content = React.createClass({ render: function() { return( <h2> HeXA @ UNIST </h2> ); } }); ReactDOM.render( <Content/>, document.getElementById(“container”) ); HeXA - 기초부2 ReactJS Tutorial
  • 11. 백문이 불여일코 HeXA @ UNIST const Content = React.createClass({ render: function() { return( <h2> {this.props.name} @ {this.props.school} </h2> ); } }); ReactDOM.render( <Content name=“HeXA” school=“UNIST”/>, document.getElementById(“container”) ); HeXA - 기초부2 ReactJS Tutorial
  • 12. 백문이 불여일코 HeXA @ UNIST const Content = React.createClass({ getDefaultProps: function() { return { name: “HeXA”, school: “UNIST” }; }, render: function() { return ( <h2> {this.props.name} @ {this.props.school} </h2> ); } }); ReactDOM.render( <Content/>, document.getElementById(“container”) ); HeXA - 기초부2 ReactJS Tutorial
  • 13. 백문이 불여일코 HeXA @ UNIST const Content = React.createClass({ getDefaultProps: function() { return { name: “HeXA”, school: “UNIST” }; }, propTypes: { name: React.PropTypes.string, school: React.PropTypes.string }, render: function() { return( <h2> {this.props.name} @ {this.props.school} </h2> ); } }); HeXA - 기초부2 ReactJS Tutorial
  • 14. 백문이 불여일코 HeXA @ UNIST 0 const Content = React.createClass({ ... getInitialState: function() { return { clicks: 0 }; }, render: function() { return( <div> <h2> {this.props.name} @ {this.props.school} </h2> <h4>{this.state.clicks}</h4> </div> ); } }); HeXA - 기초부2 ReactJS Tutorial
  • 15. 백문이 불여일코 HeXA @ UNIST 0 const Content = React.createClass({ ... getInitialState: function() { return { clicks: 0 }; }, render: function() { return( <div> <h2> {this.props.name} @ {this.props.school} </h2> <h4>{this.state.clicks}</h4> <button type=“button” onClick={this.onClick}> Increase Number </button> </div> ); }, onClick: function() { this.setState({clicks: this.state.clicks + 1}); } }); HeXA - 기초부2 ReactJS Tutorial Increase Number
  • 16. 백문이 불여일코 displayName, mixins, statics은 쓸 일 거의 없으므로 생략 const Content = React.createClass({ getDefaultProps: function() { return { name: “Name”, school: “School” }; }, propTypes: { name: React.PropTypes.string, school: React.PropTypes.string }, getInitialState: function() { return { clicks: 0 }; }, render: function() { return( <div> <h2> {this.props.name} @ {this.props.school} </h2> <h4>{this.state.clicks}</h4> <button type=“button” onClick={this.onClick}> Increase Number </button> </div> ); }, onClick: function() { this.setState({ clicks: this.state.clicks + 1 }); } }); HeXA - 기초부2 ReactJS Tutorial
  • 17. React Lifecycle • Mounting componentWillMount componentDidMount • Updating componentWillReceiveProps shouldComponentUpdate componentWillUpdate componentDidUpdate • Unmounting componentWillUnmount HeXA - 기초부2 ReactJS Tutorial
  • 18. React Lifecycle • Mounting componentWillMount : 컴포넌트 생성 전 componentDidMount : 컴포넌트 생성 후 • Updating componentWillReceiveProps : 새로운 props 받기 전 shouldComponentUpdate : 컴포넌트 업데이트 여부 componentWillUpdate : 컴포넌트 업데이트 전 componentDidUpdate : 컴포넌트 업데이트 후 • Unmounting componentWillUnmount : 컴포넌트 소멸 전 HeXA - 기초부2 ReactJS Tutorial
  • 19. React Lifecycle 예시 const Content = React.createClass({ ... componentDidMount: function() { alert(“Hi”); }, ... }); HeXA - 기초부2 ReactJS Tutorial
  • 20. React Lifecycle 예시 const Content = React.createClass({ ... componentDidMount: function() { alert(“Hi”); }, componentWillUpdate: function() { alert(“Updating”); }, ... }); HeXA - 기초부2 ReactJS Tutorial
  • 21. React Lifecycle 예시 const Content = React.createClass({ ... componentDidMount: function() { alert(“Hi”); }, shouldComponentUpdate: function(newProps, newState) { if(newProps.school == "UNIST") { return false; } else { return true; } }, componentWillUpdate: function() { alert(“Updating”); }, ... }); HeXA - 기초부2 ReactJS Tutorial
  • 22. React 컴파일 • Babel: 적용된 preset에 맞게 문법 변환을 해준다. • Webpack: 문법 변환 뿐 아니라 라이브러리까지 통합된 하나의 js파일로 만들어주며(bundle) 설정을 통한 Uglify(minify), Common chunk 등의 optimization도 지원 • Browserify: Webpack같은 js 번들 라이브러리 HeXA - 기초부2 ReactJS Tutorial
  • 23. 준비작업 NPM (Node Package Manager) 를 이용해 라이브러리 다운로드 받기 : npm install babel, webpack 다운받기(Global Toolkit) : npm install –g babel-cli webpack HeXA - 기초부2 ReactJS Tutorial
  • 24. Babel 컴파일 babel --presets react js/src/babel --out-dir js/out : --presets react > React 프리셋 적용 : js/src/babel > js/src/babel에 있는 js파일을 컴파일 : --out-dir js/out > 컴파일된 js파일을 js/out로 보냄 --watch 추가하면 파일이 변경될 때 마다 자동으로 컴파일! package.json의 scripts에 미리 선언 되어있다. npm run-script babel 입력하면 실행가능 HeXA - 기초부2 ReactJS Tutorial
  • 25. Babel 컴파일 Code [ src/Content.js ] const Content = React.createClass({ ... }); ReactDOM.render( ... ); Usage [React compiled by Babel] <script src=“react.js”> <script src=“react-dom.js”> <script src=“out/Content.js”> HeXA - 기초부2 ReactJS Tutorial
  • 26. Webpack 컴파일 webpack.config.js 파일에 설정 후 webpack 커맨드 실행 webpack --progress --colors : --progress > progress를 터미널에 출력 : --colors > 출력 결과에 색을 입혀 이쁘게 출력 --watch 추가하면 파일 변경시 자동 컴파일 마찬가지로 package.json scripts에 추가되어있음 npm run-script webpack HeXA - 기초부2 ReactJS Tutorial
  • 27. Webpack 컴파일 Code [ src/Content.js ] const React = require(‘react’); const ReactDOM = require(‘react-dom’); const Content = React.createClass({ ... }); ReactDOM.render( ... ); Usage [React compiled by Webpack] <script src=“out/Content.js”> HeXA - 기초부2 ReactJS Tutorial
  • 29. 유배지를 웹으로 구현하자 카테고리 선택 카테고리에 해당하는 배달업소 로드 이름, 전화번호, 위치 보여주기! js/src/UBaeZi 를 보고 따라해봅시다! HeXA - 기초부2 ReactJS Tutorial 유니스트 배달 지존
  • 30. 모바일 어플. 만들 수 있습니다. const React = require(‘react’); : 웹 const React = require(‘react-native’); : 어플 HeXA - 기초부2 ReactJS Tutorial