Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 정규표현식
- update
- REACTJS
- npm
- current_date
- java
- MySQL
- Express
- REACT
- log_bin
- upgrade
- git
- Effective Java 3/e
- spring
- migration
- JavaScript
- Node
- mysql 5.5
- Spring Batch
- log4j2
- expire_logs_days
- Regular expression
- Effective Java
- 퀵소트
- eslint
- Chunk
- spring cloud
- nodejs
- regex
- Webpack
Archives
- Today
- Total
내 세상
[React] Class Component / Function Component / Arrow Function 본문
Technical/React
[React] Class Component / Function Component / Arrow Function
sga8 2020. 5. 11. 16:45728x90
React Official Reference에서는 Function Component + Hooks 사용을 권장함.
Class component | Function component | |
장점 | render 함수 필수 |
선언이 편리함. 메모리 자원 덜 사용함. Build/Deploy 후 결과물 파일 크기가 더 작음. |
단점 | state / Lifecycle API 사용 불가능. → React v16.8 이후 Hooks 도입으로 해결됨. |
화살표 함수(Arrow Function)
- ES6 문법에서 함수를 표현하는 새로운 방식.
- 기존 function과 사용 용도가 조금 다름. 주로 함수를 파라미터로 전달할 때 유용함.
일반 함수(Normal Function) | 화살표 함수(Arrow Function) | |
샘플 코드 | function testFunc1() { this.name = "AAA"; return { name : "BBB", test: function() { console.log(this.name); } } } let testFunc1 = new testFunc1(); testFunc1.test(); |
function testFunc2() { this.name = "AAA"; return { name : "BBB", test: function() { console.log(this.name); } } } let testFunc2 = new testFunc2(); testFunc2.test(); |
결과 | BBB | AAA |
이유 | 자신이 종속된 객체를 this로 가리킴. | 자신이 종속된 인스턴스를 this로 가리킴. |
728x90
'Technical > React' 카테고리의 다른 글
[React] react-contextmenu에서 react-contexify로 변경한 이유 (0) | 2021.04.21 |
---|---|
[React] React Component/JSX Element to Html (0) | 2021.02.04 |
[React] Dialog 위 Component Focus Setting (0) | 2020.06.09 |
[React] Browser HTTP connetions in Node.js (0) | 2020.05.14 |
[React] JSX / const, let, var (0) | 2020.05.11 |