SlideShare a Scribd company logo
1 of 34
Download to read offline
컴포넌트
Component
이재민
2018년 9월
src/MyComponent.js 생성
컴포넌트 만들기
실행 결과
props
props
Properties를 줄인 표현으로 컴포넌트의 속성을 설정할 때 사용하는 요소
부모 컴포넌트에서만 설정이 가능함
JSX 내부에서 props 렌더링
props에 접근할 때는 this키워드를 사용하여 접근할 수 있다.
컴포넌트 사용할 때 props 값 설정
Props 기본 값 설정: defaultProps
props에 name을 제거하고 컴파일 하면
Props 기본 값 설정: defaultProps
Props 기본 값 설정: defaultProps
transfrom-class-properties
Props 검증: propsTypes
transfrom-class-properties
Props 검증을 위해서는 prop-types 모듈을 import 해야한다.
Props 검증: propsTypes
Props 검증: propsTypes
transfrom-class-properties
Props 검증: propsTypes
필수 props 등록
필수 props 등록
필수 props 등록
propTypes 의 종류
array: 배열
bool: 참, 거짓
func: 함수
number: 숫자
object: 객체
string: 문자열
symbol: ES6 문법의 심벌 객체
node: 렌더링할 수 있는 모든 것
element: 리엑트 요소
instanceOf: 특정 클래스의 인터페이스
oneOf: 주어진 배열 요소 값 중 하나
oneOfType: 주어진 배열안의 종류 중 하나
arrayOf: 주어진 종류로 구성된 배열
objectOf: 주어진 종류의 값은 가진 객체
shape: 주어진 스키마를 가진 객체
any: 아무 종류
props는 읽기 전용으로만 사용이 가능!
props는 읽기 전용으로만 사용이 가능!
내부에서 데이터를 업데이트 하려면 state를 써야함
state
반드시 this.setState()를 사용해서 업데이트를 해야함
this.setState()사용하지 않고 직접 업데이트시 리렌더링이 발생하지 않음!
state
반드시 this.setState()를 사용해서 업데이트를 해야함
this.setState()사용하지 않고 직접 업데이트시 리렌더링이 발생하지 않음!
state 사용하기
state는 컴포넌트의 생성자에서 초기화를 할 수있다!
state 사용하기
state는 컴포넌트의 생성자에서 초기화를 할 수있다!
생성자를 사용하기 위해 super()로
Component 에게 props를 전달한다.
state 사용하기
JSX 내부에서 랜더링
this.state.stateName 을 사용하여 state에 접근할 수 있습니다!
JSX 내부에서 랜더링
state 값 업데이트
Transform-class-properties문법을 사용해
생성자에서 state 꺼내기
create-reat-app 에 webpack 설정이 되어있으므로
별도의 설정은 필요 없다!
state 값 업데이트시 주의할점
반드시 this.setState()를 사용해서 업데이트를 해야함
this.setState()사용하지 않고 직접 업데이트시 리렌더링이 발생하지 않음!
state 값 업데이트시 주의할점
반드시 this.setState()를 사용해서 업데이트를 해야함
this.setState()사용하지 않고 직접 업데이트시 리렌더링이 발생하지 않음!
단, 필요에 따라 this.forceUpdate() 메서드를 호출하여
강제로 리렌더링이 가능
이것은 매우 비효율 적이다.

More Related Content

What's hot

Effective c++ 1
Effective c++ 1Effective c++ 1
Effective c++ 1
현찬 양
 
이펙티브 C++ 공부
이펙티브 C++ 공부이펙티브 C++ 공부
이펙티브 C++ 공부
quxn6
 
More effective c++ 1
More effective c++ 1More effective c++ 1
More effective c++ 1
현찬 양
 
[아꿈사] The C++ Programming Language 13장 템플릿
[아꿈사] The C++ Programming Language 13장 템플릿[아꿈사] The C++ Programming Language 13장 템플릿
[아꿈사] The C++ Programming Language 13장 템플릿
해강
 
More effective c++ 3
More effective c++ 3More effective c++ 3
More effective c++ 3
현찬 양
 
Effective c++ chapter 7,8
Effective c++ chapter 7,8Effective c++ chapter 7,8
Effective c++ chapter 7,8
문익 장
 

What's hot (20)

Effective c++ 1
Effective c++ 1Effective c++ 1
Effective c++ 1
 
[SwiftStudy 2016] 3장. 함수
[SwiftStudy 2016] 3장. 함수[SwiftStudy 2016] 3장. 함수
[SwiftStudy 2016] 3장. 함수
 
[SwiftStudy 2016] 2장. Swift 타입 파트 1
[SwiftStudy 2016] 2장. Swift 타입 파트 1[SwiftStudy 2016] 2장. Swift 타입 파트 1
[SwiftStudy 2016] 2장. Swift 타입 파트 1
 
Use JavaScript more strictly (feat. TypeScript, flow)
Use JavaScript more strictly (feat. TypeScript, flow)Use JavaScript more strictly (feat. TypeScript, flow)
Use JavaScript more strictly (feat. TypeScript, flow)
 
More effective c++ chapter1 2_dcshin
More effective c++ chapter1 2_dcshinMore effective c++ chapter1 2_dcshin
More effective c++ chapter1 2_dcshin
 
[Osxdev]4.swift
[Osxdev]4.swift[Osxdev]4.swift
[Osxdev]4.swift
 
Junit jasmine
Junit jasmineJunit jasmine
Junit jasmine
 
이펙티브 C++ 공부
이펙티브 C++ 공부이펙티브 C++ 공부
이펙티브 C++ 공부
 
Effective c++ chapter3, 4 요약본
Effective c++ chapter3, 4 요약본Effective c++ chapter3, 4 요약본
Effective c++ chapter3, 4 요약본
 
[1B1]스위프트프로그래밍언어
[1B1]스위프트프로그래밍언어[1B1]스위프트프로그래밍언어
[1B1]스위프트프로그래밍언어
 
More effective c++ 1
More effective c++ 1More effective c++ 1
More effective c++ 1
 
effective c++ chapter 3~4 정리
effective c++ chapter 3~4 정리effective c++ chapter 3~4 정리
effective c++ chapter 3~4 정리
 
Effective c++ 1,2
Effective c++ 1,2Effective c++ 1,2
Effective c++ 1,2
 
07. type system
07. type system07. type system
07. type system
 
[아꿈사] The C++ Programming Language 13장 템플릿
[아꿈사] The C++ Programming Language 13장 템플릿[아꿈사] The C++ Programming Language 13장 템플릿
[아꿈사] The C++ Programming Language 13장 템플릿
 
More effective c++ 3
More effective c++ 3More effective c++ 3
More effective c++ 3
 
01. basic types
01. basic types01. basic types
01. basic types
 
이펙티브 C++ 5,6 장 스터디
이펙티브 C++ 5,6 장 스터디이펙티브 C++ 5,6 장 스터디
이펙티브 C++ 5,6 장 스터디
 
Effective c++ chapter 7,8
Effective c++ chapter 7,8Effective c++ chapter 7,8
Effective c++ chapter 7,8
 
Effective java 1 and 2
Effective java 1 and 2Effective java 1 and 2
Effective java 1 and 2
 

Similar to 04 component

[IT기술칼럼#2] 고급자바스크립트 for AngularJS, React_고급자바스크립트,AngularJS,React전문교육학원
[IT기술칼럼#2] 고급자바스크립트 for AngularJS, React_고급자바스크립트,AngularJS,React전문교육학원[IT기술칼럼#2] 고급자바스크립트 for AngularJS, React_고급자바스크립트,AngularJS,React전문교육학원
[IT기술칼럼#2] 고급자바스크립트 for AngularJS, React_고급자바스크립트,AngularJS,React전문교육학원
탑크리에듀(구로디지털단지역3번출구 2분거리)
 

Similar to 04 component (6)

Openface
OpenfaceOpenface
Openface
 
파이썬 함수 이해하기
파이썬 함수 이해하기 파이썬 함수 이해하기
파이썬 함수 이해하기
 
[IT기술칼럼#2] 고급자바스크립트 for AngularJS, React_고급자바스크립트,AngularJS,React전문교육학원
[IT기술칼럼#2] 고급자바스크립트 for AngularJS, React_고급자바스크립트,AngularJS,React전문교육학원[IT기술칼럼#2] 고급자바스크립트 for AngularJS, React_고급자바스크립트,AngularJS,React전문교육학원
[IT기술칼럼#2] 고급자바스크립트 for AngularJS, React_고급자바스크립트,AngularJS,React전문교육학원
 
자바카페 스터디- INSIDE JS 1-3
자바카페 스터디- INSIDE JS 1-3자바카페 스터디- INSIDE JS 1-3
자바카페 스터디- INSIDE JS 1-3
 
스파르탄Js in sidejs4
스파르탄Js in sidejs4스파르탄Js in sidejs4
스파르탄Js in sidejs4
 
React 실무활용 이야기
React 실무활용 이야기React 실무활용 이야기
React 실무활용 이야기
 

More from Jay Lee (6)

Https
HttpsHttps
Https
 
03 jsx
03 jsx03 jsx
03 jsx
 
02 install-react-js
02 install-react-js02 install-react-js
02 install-react-js
 
01 introduce-react-js
01 introduce-react-js01 introduce-react-js
01 introduce-react-js
 
Codeveloper 개발기
Codeveloper 개발기Codeveloper 개발기
Codeveloper 개발기
 
Codeveloper
CodeveloperCodeveloper
Codeveloper
 

04 component