GithubHelp home page GithubHelp logo

seonhyungjo / reactjs-interview-questions-korean Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sudheerj/reactjs-interview-questions

75.0 1.0 19.0 2.48 MB

List of top 500 ReactJS Interview Questions & Answers....Coding exercise questions are coming soon!!

reactjs react-router redux javascript javascript-framework react-native interview-questions interview-preparation react react-interview-questions javascript-interview-questions react16 javascript-applications korean

reactjs-interview-questions-korean's Introduction

React Interview Questions & Answers


Having Tech Interview?
3600 Tech Interview Questions. Answered.

FullStack.Cafe
Proudly supporting React Interview Questions


Downloading PDF/Epub formats

You can download the PDF and Epub version of this repository from the latest run on the actions tab.

Contributor

  • ๐Ÿ“‹ ๋ณธ ๋ฌธ์„œ๋Š” sudheerj์˜ reactjs-interview-questions์˜ ๋ฒˆ์—ญ๋ณธ์ž…๋‹ˆ๋‹ค.
  • โญ ์ด ํ”„๋กœ์ ํŠธ๊ฐ€ ๋งˆ์Œ์— ๋“œ์…จ๋‹ค๋ฉด STAR๋ฅผ ๋ˆŒ๋Ÿฌ์ฃผ์„ธ์š”.
  • โœ”๏ธ ํ’€ ๋ฆฌํ€˜์ŠคํŠธ๋Š” ์–ธ์ œ๋“  ํ™˜์˜์ž…๋‹ˆ๋‹ค.
  • ๐Ÿ‘ vuejs-interview-questions-korean๋ฅผ ์ฐธ๊ณ ๋ฅผ ํ•ด์„œ ์ž‘์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค.

Table of Contents

No. Questions
Core React
1 React๋ž€ ๋ฌด์—‡์ธ๊ฐ€?
2 React์˜ ์ฃผ์š” ํŠน์ง•์€?
3 JSX๋ž€ ๋ฌด์—‡์ธ๊ฐ€?
4 Element์™€ Component์˜ ์ฐจ์ด์ ์€?
5 React์—์„œ components๋Š” ์–ด๋–ป๊ฒŒ ๋งŒ๋“œ๋‚˜?
6 ์–ธ์ œ Function Component ๋Œ€์‹ ์— Class Component๋ฅผ ์‚ฌ์šฉํ•˜๋‚˜?
7 Pure Components๋ž€ ๋ฌด์—‡์ธ๊ฐ€?
8 React์—์„œ state๋Š” ๋ฌด์—‡์ธ๊ฐ€?
9 React์—์„œ props๋Š” ๋ฌด์—‡์ธ๊ฐ€?
10 state์™€ prop์˜ ์ฐจ์ด์ ์€?
11 ์™œ state๋ฅผ ์ง์ ‘ updateํ•˜๋ฉด ์•ˆ๋˜๋‚˜?
12 setState()์˜ argument๋กœ callback ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ๋Š”?
13 HTML๊ณผ React์˜ event handling์˜ ์ฐจ์ด์ ์€?
14 ์–ด๋–ป๊ฒŒ JSX ์ฝœ๋ฐฑ์—์„œ ๋ฉ”์„œ๋“œ์™€ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ๋ฅผ ๋ฐ”์ธ๋“œํ•˜๋‚˜?
15 ์–ด๋–ป๊ฒŒ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ๋‚˜ ์ฝœ๋ฐฑ์— ๋งค๊ฐœ ๋ณ€์ˆ˜๋ฅผ ์ „๋‹ฌํ•˜๋‚˜?
16 React์— SyntheticEvent๋ž€ ๋ฌด์—‡์ธ๊ฐ€?
17 ์ธ๋ผ์ธ ์กฐ๊ฑด ํ‘œํ˜„์‹์ด๋ž€?
18 "key" props๋Š” ๋ฌด์—‡์ด๋ฉฐ elements์˜ ๋ฐฐ์—ด์—์„œ ์‚ฌ์šฉํ•˜๋ฉด ์ด์ ์ด ๋ฌด์—‡์ธ๊ฐ€?
19 refs๋Š” ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉ๋˜๋Š”๊ฐ€?
20 refs๋Š” ์–ด๋–ป๊ฒŒ ์ƒ์„ฑํ•˜๋Š”๊ฐ€?
21 forward refs๋Š” ๋ฌด์—‡์ธ๊ฐ€?
22 callback refs ๋ฐ findDOMNode()์—์„œ ์„ ํ˜ธ๋˜๋Š” ์˜ต์…˜์€?
23 String Refs๊ฐ€ ์™œ legacy์ธ๊ฐ€?
24 Virtual DOM์ด๋ž€?
25 Virtual DOM์€ ์–ด๋–ป๊ฒŒ ์ž‘๋™ํ•˜๋‚˜?
26 Shadow DOM๊ณผ Virtual DOM์˜ ์ฐจ์ด์ 
27 React Fiber๋ž€?
28 React Fiber์˜ ์ฃผ์š” ๋ชฉํ‘œ๋Š”?
29 controlled components๋ž€?
30 uncontrolled components๋ž€?
31 createElement์™€ cloneElement์˜ ์ฐจ์ด์ ์€?
32 React์—์„œ Lifting State Up๋ž€?
33 ์ปดํฌ๋„ŒํŠธ ๋ผ์ดํ”„ ์‚ฌ์ดํด์˜ ๋‹ค๋ฅธ ๋‹จ๊ณ„๋“ค์€?
34 React์˜ ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์„œ๋“œ์—๋Š” ๋ฌด์—‡์ด ์žˆ๋‚˜?
35 ๊ณ ์ฐจ(Higher-Order) ์ปดํฌ๋„ŒํŠธ๋ž€?
36 HOC ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•ด์„œ props ํ”„๋ก์‹œ๋ฅผ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์€?
37 context๋ž€?
38 children prop์ด๋ž€?
39 React์—์„œ ์ฃผ์„์„ ์–ด๋–ป๊ฒŒ ๋‹ค๋Š”๊ฐ€?
40 props argument๊ฐ€ ์žˆ๋Š” ์ƒ์„ฑ์ž์—์„œ super๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ชฉ์ ์€ ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?
41 ์กฐ์ •(reconciliation)์ด๋ž€?
42 state์˜ ํ‚ค ์ด๋ฆ„์„ ๋™์ ์œผ๋กœ ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
43 ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ Œ๋”๋ง ๋  ๋•Œ๋งˆ๋‹ค ํ˜ธ์ถœ๋˜๋Š” ํ•จ์ˆ˜์— ๋Œ€ํ•œ ์‹ค์ˆ˜๋Š” ๋ฌด์—‡์ผ๊นŒ?
44 ์™œ ์ปดํฌ๋„ŒํŠธ ์ด๋ฆ„์€ ๋Œ€๋ฌธ์ž๋กœ ํ•ด์•ผ ํ•˜๋‚˜?
45 React๋Š” ์™œ class๊ฐ€ ์•„๋‹Œ className ์†์„ฑ์„ ์‚ฌ์šฉํ•˜๋‚˜?
46 fragments๋ž€?
47 div๋ณด๋‹ค fragments๊ฐ€ ๋” ์šฐ์ˆ˜ํ•œ ์ด์œ ๋Š”?
48 React์˜ portals์ด๋ž€?
49 stateless ์ปดํฌ๋„ŒํŠธ๋ž€?
50 stateful ์ปดํฌ๋„ŒํŠธ๋ž€?
51 React์—์„œ props ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฅผ ์ ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
52 React์˜ ์žฅ์ ์€?
53 React์˜ ํ•œ๊ณ„๋Š”?
54 React v16์—์„œ error boundaries๋ž€ ๋ฌด์—‡์ธ๊ฐ€?
55 React v15์—์„œ๋Š” ์–ด๋–ป๊ฒŒ error boundaries ์กฐ์ž‘ํ•˜๋‚˜?
56 ์ •์  ํƒ€์ž… ๊ฒ€์‚ฌ์— ๊ถŒ์žฅ๋˜๋Š” ๋ฐฉ๋ฒ•์€?
57 react-dom ํŒจํ‚ค์ง€ ์‚ฌ์šฉ๋ฒ•์€?
58 react-dom์˜ render ๋ฉ”์„œ๋“œ๋ž€?
59 ReactDOMServer๋ž€?
60 React์—์„œ innerHTML๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•?
61 React์—์„œ ์Šคํƒ€์ผ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•?
62 React์—์„œ ์ด๋ฒคํŠธ๊ฐ€ ์–ด๋–ป๊ฒŒ ๋‹ค๋ฅธ๊ฐ€?
63 ์ƒ์„ฑ์ž์—์„œ setState()๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์–ด๋–ป๊ฒŒ ๋˜๋‚˜?
64 ํ‚ค๋กœ ์ธ๋ฑ์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด?
65 componentWillMount() ๋ฉ”์„œ๋“œ์—์„œ setState()๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ ์ข‹์€๊ฐ€?
66 ์ดˆ๊ธฐ state์— props๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์–ด๋–ป๊ฒŒ ๋˜๋‚˜?
67 ์ปดํฌ๋„ŒํŠธ๋ฅผ ์กฐ๊ฑด๋ถ€๋กœ ๋ Œ๋”๋งํ•˜๋Š” ๋ฐฉ๋ฒ•?
68 DOM ์—˜๋ฆฌ๋จผํŠธ์—์„œ spread props๋ฅผ ์กฐ์‹ฌํ•ด์•ผํ•˜๋Š” ์ด์œ ๋Š”?
69 React์—์„œ ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•?
70 ์ปดํฌ๋„ŒํŠธ๋ฅผ ์–ด๋–ป๊ฒŒ ๋ฉ”๋ชจํ•˜๋‚˜?
71 Server Side Rendering ๋˜๋Š” SSR ๊ตฌํ˜„๋ฐฉ๋ฒ•?
72 React์—์„œ production ๋ชจ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•?
73 CRA๋ž€ ๋ฌด์—‡์ด๋ฉฐ ์žฅ์ ์€?
74 ๋งˆ์šดํŒ…์˜ ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์„œ๋“œ ์ˆœ์„œ๋Š”?
75 What are the lifecycle methods going to be deprecated in React v16?
76 getDerivedStateFromProps() ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์„œ๋“œ์˜ ์‚ฌ์šฉ ๋ชฉ์ ์€?
77 getSnapshotBeforeUpdate() ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์„œ๋“œ์˜ ์‚ฌ์šฉ ๋ชฉ์ ์€?
78 Hooks๋Š” ๋ Œ๋”๋ง props์™€ ๊ณ ์ฐจ์› ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋Œ€์ฒดํ•œ๋‹ค?
79 ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ช…๋ช…ํ•˜๋Š”๋ฐ ๊ถŒ์žฅ๋˜๋Š” ๋ฐฉ๋ฒ•์€?
80 ์ปดํฌ๋„ŒํŠธ ํด๋ž˜์Šค์—์„œ ๊ถŒ์žฅ๋˜๋Š” ๋ฉ”์„œ๋“œ ์ˆœ์„œ๋Š”?
81 ์Šค์œ„์นญ ์ปดํฌ๋„ŒํŠธ๋ž€?
82 ์™œ setState()์— ํ•จ์ˆ˜๋ฅผ ์ „๋‹ฌํ•ด์•ผ ํ•˜๋‚˜?
83 React์˜ strict mode๋ž€?
84 React Mixins์ด๋ž€?
85 ์™œ isMounted()๊ฐ€ ์•ˆํ‹ฐ ํŒจํ„ด์ด๋ฉฐ ์ ์ ˆํ•œ ํ•ด๊ฒฐ์ฑ…์€?
86 React์—์„œ ์ง€์›๋˜๋Š” Pointer Events๋Š”?
87 ์™œ ์ปดํฌ๋„ŒํŠธ์˜ ์ด๋ฆ„์€ ๋Œ€๋ฌธ์ž๋กœ ์‹œ์ž‘ํ•˜๋‚˜?
88 React v16์—์„œ ์‚ฌ์šฉ์ž ์ •์˜ DOM ์†์„ฑ์„ ์ง€์›ํ•˜๋‚˜?
89 constructor๊ณผ getInitialState์˜ ์ฐจ์ด์ ์€?
90 setState๋ฅผ ํ˜ธ์ถœํ•˜์ง€ ์•Š๊ณ ๋„ ์ปดํฌ๋„ŒํŠธ ๋ฆฌ๋ Œ๋”๋ง์ด ๊ฐ€๋Šฅํ•œ๊ฐ€?
91 ES6 ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” React์—์„œ super()์™€ super(props)์˜ ์ฐจ์ด์ ์€?
92 JSX ๋‚ด๋ถ€์—์„œ ๋ฐ˜๋ณตํ•˜๋Š” ๋ฐฉ๋ฒ•?
93 ์†์„ฑ ์ธ์šฉ๋ฌธ์— props๋ฅผ ์–ด๋–ป๊ฒŒ ๋„ฃ๋‚˜?
94 ๋ชจ์–‘์ด ์žˆ๋Š” React proptype array๋ž€?
95 ํด๋ž˜์Šค ์†์„ฑ์„ ์กฐ๊ฑด๋ถ€๋กœ ์ ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
96 React์™€ ReactDOM์˜ ์ฐจ์ด์ ?
97 ์™œ ReactDOM์€ React์™€ ๋ถ„๋ฆฌ๋˜์—ˆ๋‚˜?
98 React ๋ผ๋ฒจ ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
99 ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์ธ๋ผ์ธ ์Šคํƒ€์ผ ๊ฐ์ฒด๋ฅผ ๊ฒฐํ•ฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
100 ๋ธŒ๋ผ์šฐ์ € ํฌ๊ธฐ๋ฅผ ์กฐ์ •ํ•  ๋•Œ ๋ทฐ๋ฅผ ๋ฆฌ๋ Œ๋”๋งํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
101 setState()์™€ replaceState() ๋ฉ”์„œ๋“œ์˜ ์ฐจ์ด์ ์€?
102 state ๋ณ€๊ฒฝ์„ ์ธ์ง€ํ•˜๋Š” ๋ฐฉ๋ฒ•?
103 React state์—์„œ ๋ฐฐ์—ด ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ์ œ๊ฑฐํ•˜๋Š” ๊ถŒ์žฅ ๋ฐฉ๋ฒ•์€?
104 HTML ๋ Œ๋”๋ง์—†์ด React๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‚˜?
105 React์—์„œ JSON์„ ์ด์˜๊ฒŒ ์ถœ๋ ฅํ•˜๋Š” ๋ฐฉ๋ฒ•?
106 React์—์„œ props๋ฅผ ์—…๋ฐ์ดํŠธํ•  ์ˆ˜ ์—†๋Š” ์ด์œ ๋Š”?
107 ํŽ˜์ด์ง€ ๋กœ๋“œ ์‹œ input ์—˜๋ฆฌ๋จผํŠธ์— ํฌ์ปค์Šค๋ฅผ ์ฃผ๋Š” ๋ฐฉ๋ฒ•์€?
108 What are the possible ways of updating objects in state?
109 ์™œ ํ•จ์ˆ˜๊ฐ€ setState() ๊ฐ์ฒด๋ณด๋‹ค ์„ ํ˜ธ๋˜๋Š”๊ฐ€?
110 ๋ธŒ๋ผ์šฐ์ € ๋Ÿฐํƒ€์ž„์— React ๋ฒ„์ „์„ ์–ด๋–ป๊ฒŒ ์•Œ ์ˆ˜ ์žˆ๋‚˜?
111 create-react-app์— polyfill์„ ํฌํ•จ์‹œํ‚ค๋Š” ๋ฐฉ๋ฒ•์€?
112 create-react-app์—์„œ http ๋Œ€์‹  https๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•?
113 How to avoid using relative path imports in create-react-app?
114 React Router์šฉ Google ์›น ๋กœ๊ทธ ๋ถ„์„์„ ์ถ”๊ฐ€ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
115 ๋งค ์ดˆ๋งˆ๋‹ค ์ปดํฌ๋„ŒํŠธ๋ฅผ ์—…๋ฐ์ดํŠธ ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
116 React์—์„œ ์ธ๋ผ์ธ ์Šคํƒ€์ผ์— ๋ฒค๋” ์ ‘๋‘์‚ฌ๋Š” ์–ด๋–ป๊ฒŒ ์ ์šฉํ•˜๋‚˜?
117 React์™€ ES6๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ฐ€์ ธ์˜ค๊ณ  ๋‚ด๋ณด๋‚ด๋Š” ๋ฐฉ๋ฒ•์€?
118 React ์ปดํฌ๋„ŒํŠธ ์ด๋ฆ„์ด ๋Œ€๋ฌธ์ž๋กœ ์‹œ์ž‘ํ•ด์•ผ ํ•˜๋Š” ์ด์œ ๋Š”?
119 ์ปดํฌ๋„ŒํŠธ ์ƒ์„ฑ์ž๋Š” ์™œ ํ•œ ๋ฒˆ๋งŒ ๋ถˆ๋ฆฌ๋‚˜?
120 React์—์„œ ์ƒ์ˆ˜๋ฅผ ์ •์˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
121 React์—์„œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ฐฉ์‹์œผ๋กœ ํด๋ฆญ ์ด๋ฒคํŠธ๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๋Š” ๋ฐฉ๋ฒ•์€?
122 async/await๋ฅผ ํ‰๋ฒ”ํ•œ React์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‚˜?
123 React์˜ ์ผ๋ฐ˜์ ์ธ ํด๋” ๊ตฌ์กฐ๋Š”?
124 ์ธ๊ธฐ ์• ๋‹ˆ๋ฉ”์ด์…˜ ํŒจํ‚ค์ง€๋Š”?
125 ์Šคํƒ€์ผ ๋ชจ๋“ˆ์˜ ์ด์ ์€?
126 ์ธ๊ธฐ์žˆ๋Š” React-๊ด€๋ จ linters๋Š”?
127 AJAX ํ˜ธ์ถœํ•˜๋Š” ๋ฐฉ๋ฒ•๊ณผ ์–ด๋Š ์ปดํฌ๋„ŒํŠธ ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์„œ๋“œ์—์„œ AJAX ํ˜ธ์ถœ์„ ํ•ด์•ผํ•˜๋‚˜?
128 render props๋ž€?
React Router
129 React Router๋ž€?
130 React Router๊ฐ€ history ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€ ๋‹ค๋ฅธ์ ์€?
131 Router v4์˜ <Router> ์ปดํฌ๋„ŒํŠธ๋Š” ๋ฌด์—‡์ธ๊ฐ€?
132 history์˜ push, place ๋ฉ”์„œ๋“œ์˜ ๋ชฉ์ ์€?
133 React Router v4๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ฐฉ์‹์œผ๋กœ ์–ด๋–ป๊ฒŒ ํƒ์ƒ‰ํ•˜๋‚˜?
134 React Router v4์—์„œ ์ฟผ๋ฆฌ ๋งค๊ฐœ ๋ณ€์ˆ˜๋ฅผ ์–ป๋Š” ๋ฐฉ๋ฒ•์€?
135 ์™œ Router may have only one child element๋ผ๋Š” ๊ฒฝ๊ณ  ๋ฉ”์‹œ์ง€๊ฐ€ ๋‚˜์˜ค๋‚˜?
136 React Router v4์˜ history.push ๋ฉ”์„œ๋“œ์— ๋งค๊ฐœ ๋ณ€์ˆ˜๋ฅผ ์ „๋‹ฌํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
137 default ๋˜๋Š” NotFound ํŽ˜์ด์ง€ ๊ตฌํ˜„ ๋ฐฉ๋ฒ•?
138 React Router v4์—์„œ history๋ฅผ ์–ป๋Š” ๋ฐฉ๋ฒ•์€?
139 ๋กœ๊ทธ์ธ ํ›„ ์ž๋™ ๋ฆฌ๋””๋ ‰์…˜์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
React Internationalization
140 What is React-Intl?
141 What are the main features of React Intl?
142 What are the two ways of formatting in React Intl?
143 How to use FormattedMessage as placeholder using React Intl?
144 How to access current locale with React Intl
145 How to format date using React Intl?
React Testing
146 What is Shallow Renderer in React testing?
147 What is TestRenderer package in React?
148 What is the purpose of ReactTestUtils package?
149 What is Jest?
150 What are the advantages of Jest over Jasmine?
151 Give a simple example of Jest test case
React Redux
152 flux๋ž€?
153 Redux๋ž€?
154 Redux์˜ ํ•ต์‹ฌ ์›์น™์€?
155 Flux์™€ ๋น„๊ตํ•œ Redux์˜ ๋‹จ์ ์€?
156 mapStateToProps()๊ณผ mapDispatchToProps()์˜ ์ฐจ์ด์ ์€?
157 reducer์—์„œ action์„ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋‚˜?
158 ์ปดํฌ๋„ŒํŠธ ์™ธ๋ถ€์˜ Redux store์— ์ ‘๊ทผํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
159 MVW ํŒจํ„ด์˜ ๋‹จ์ ์€ ๋ฌด์—‡์ธ๊ฐ€
160 Redux์™€ RxJS์˜ ๋น„์Šทํ•œ ์ ์€?
161 ๋กœ๋“œ ์‹œ์ ์— action์„ ์ „๋‹ฌํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
162 React Redux์—์„œ connect()๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
163 Redux์—์„œ state๋ฅผ ์žฌ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
164 Whats the purpose of at symbol in the redux connect decorator?
165 React context์™€ React Redux์˜ ์ฐจ์ด์ ์€?
166 Redux state ํ•จ์ˆ˜๊ฐ€ reducer๋ผ๊ณ  ๋ถˆ๋ฆฌ๋Š” ์ด์œ ๋Š”?
167 Redux์—์„œ AJAX๋ฅผ ์š”์ฒญํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
168 Should I keep all component's state in Redux store?
169 Redux store์— ์ ‘๊ทผํ•˜๋Š” ์˜ฌ๋ฐ”๋ฅธ ๋ฐฉ๋ฒ•์€?
170 React Redux์—์„œ ์ปดํฌ๋„ŒํŠธ์™€ ์ปจํ…Œ์ด๋„ˆ์˜ ์ฐจ์ด์ ์€?
171 Redux์—์„œ ์ƒ์ˆ˜์˜ ๋ชฉ์ ์€ ๋ฌด์—‡์ธ๊ฐ€?
172 mapDispatchToProps()๋ฅผ ์ž‘์„ฑํ•˜๋Š” ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์€?
173 mapStateToProps() ๊ณผ mapDispatchToProps()์—์„œ ownProps ๋งค๊ฐœ ๋ณ€์ˆ˜์˜ ์‚ฌ์šฉ๋ฐฉ๋ฒ•์€?
174 Redux ์ตœ์ƒ์œ„ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
175 redux-saga๋ž€?
176 redux-saga์˜ ์ •์‹  ๋ชจ๋ธ์€?
177 redux-saga์—์„œ call๊ณผ put์˜ ์ฐจ์ด์ ์€?
178 Redux Thunk๋ž€?
179 redux-saga์™€ redux-thunk์˜ ์ฐจ์ด์ ์€?
180 Redux DevTools์ด๋ž€?
181 Redux DevTools์˜ ๊ธฐ๋Šฅ์—๋Š” ๋ฌด์—‡์ด ์žˆ๋‚˜?
182 Redux selectors๊ฐ€ ๋ฌด์—‡์ด๋ฉฐ ์‚ฌ์šฉํ•ด์•ผํ•˜๋Š” ์ด์œ ๋Š”?
183 Redux Form์ด๋ž€?
184 Redux Form์˜ ์ฃผ์š” ๊ธฐ๋Šฅ์€?
185 Redux์— ์—ฌ๋Ÿฌ ๋ฏธ๋“ค์›จ์–ด๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
186 Redux์—์„œ ์ดˆ๊ธฐ state๋ฅผ ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
187 Relay์™€ Redux์˜ ์ฐจ์ด์ ์€?
React Native
188 What is the difference between React Native and React?
189 How to test React Native apps?
190 How to do logging in React Native?
191 How to debug your React Native?
React supported libraries and Integration
192 reselect์ด๋ž€ ๋ฌด์—‡์ด๋ฉฐ ์–ด๋–ป๊ฒŒ ์ž‘๋™ํ•˜๋‚˜?
193 Flow๋ž€?
194 Flow์™€ PropTypes์˜ ์ฐจ์ด์ ์€?
195 React์—์„œ Font Awesome icons๋ฅผ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋‚˜?
196 React Dev Tools์ด๋ž€?
197 ๋กœ์ปฌ ํŒŒ์ผ์„ ์—ฐ Chrome์—์„œ DevTools์ด ๋กœ๋”ฉ๋˜์ง€ ์•Š๋Š” ์ด์œ ๋Š”?
198 React์—์„œ Polymer๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
199 Vue.js๋ณด๋‹ค React์˜ ์žฅ์ ์€ ๋ฌด์—‡์ธ๊ฐ€?
200 React์™€ Angular์˜ ์ฐจ์ด์ ์€?
201 DevTools์— React ํƒญ์ด ํ‘œ์‹œ๋˜์ง€ ์•Š๋Š” ์ด์œ ๋Š”?
202 Styled Components๋ž€?
203 Styled Components์˜ ์˜ˆ์‹œ๋Š”?
204 Relay๋ž€?
205 create-react-app ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ TypeScript๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•?
Miscellaneous
206 Reselect ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ์ฃผ์š” ๊ธฐ๋Šฅ์€?
207 Reselect ์‚ฌ์šฉ๋ฒ•์— ๋Œ€ํ•œ ์˜ˆ์‹œ๋Š”?
208 Redux์—์„œ action์ด๋ž€?
209 React์˜ ES6 ํด๋ž˜์Šค๋Š” static object์™€ ํ•จ๊ป˜ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ๊ฐ€?
210 Redux๋Š” React์—์„œ๋งŒ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ๊ฐ€?
211 Redux๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ํŠน๋ณ„ํ•œ ๋นŒ๋“œ ๋„๊ตฌ๊ฐ€ ํ•„์š”ํ•œ๊ฐ€?
212 Redux Form initialValues๋Š” state์—์„œ ์–ด๋–ป๊ฒŒ ์—…๋ฐ์ดํŠธํ•˜๋‚˜?
213 React PropTypes์ด ํ•˜๋‚˜์˜ prop์—์„œ ๋‹ค๋ฅธ ํƒ€์ž…๋“ค์„ ํ—ˆ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
214 SVG file์„ react ์ปดํฌ๋„ŒํŠธ๋กœ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๋‚˜?
215 ์ธ๋ผ์ธ ref ์ฝœ๋ฐฑ ๋˜๋Š” ํ•จ์ˆ˜๋ฅผ ๊ถŒ์žฅํ•˜์ง€ ์•Š๋Š” ์ด์œ ๋Š”?
216 react์—์„œ render hijacking์ด๋ž€?
217 HOC ํŒฉํ† ๋ฆฌ ๊ตฌํ˜„์ด๋ž€?
218 React ์ปดํฌ๋„ŒํŠธ์— ์ˆซ์ž๋ฅผ ์ „๋‹ฌํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
219 ๋ชจ๋“  state๋ฅผ Redux์—์„œ ๊ด€๋ฆฌ๋ฅผ ํ•ด์•ผํ•˜๋‚˜? react ๋‚ด๋ถ€ state๋ฅผ ์‚ฌ์šฉํ•ด์•ผํ•˜๋‚˜?
220 React์—์„œ registerServiceWorker์˜ ๋ชฉ์ ์€?
221 React์˜ memo ํ•จ์ˆ˜๋ž€?
222 React์˜ lazy function๋ž€?
223 setState๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๋ฐ ์žˆ์–ด ๋ถˆํ•„์š”ํ•œ ์—…๋ฐ์ดํŠธ๋ฅผ ๋ฐฉ์ง€ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
224 React 16๋ฒ„์ „์—์„œ Array, Strings์™€ Numbers๋ฅผ ๋ Œ๋”๋งํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
225 React ํด๋ž˜์Šค์—์„œ ํด๋ž˜์Šค ํ•„๋“œ ์„ ์–ธ ๊ตฌ๋ฌธ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
226 hooks์ด๋ž€?
227 hooks๋ฅผ ์œ„ํ•ด์„œ ์ง€์ผœ์•ผ ํ•˜๋Š” ๊ทœ์น™์€ ๋ฌด์—‡์ธ๊ฐ€?
228 hooks๊ฐ€ ํ”„๋กœ์ ํŠธ์˜ ๊ทœ์น™์„ ์ค€์ˆ˜ํ•˜๋„๋ก ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
229 Flux์™€ Redux์˜ ์ฐจ์ด์ ์€?
230 React Router V4์˜ ์žฅ์ ์€?
231 componentDidCatch ์ƒ๋ช…์ฃผ๊ธฐ ๋ฉ”์„œ๋“œ์— ๋Œ€ํ•ด์„œ ์„ค๋ช…ํ•  ์ˆ˜ ์žˆ๋‚˜?
232 ์–ด๋–ค ์—๋Ÿฌ ๋ฐ”์šด๋”๋ฆฌ(error boundary)์—์„œ ์žก์ง€ ๋ชปํ• ๊นŒ?
233 ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ์— ์—๋Ÿฌ ๋ฐ”์šด๋”๋ฆฌ๊ฐ€ ํ•„์š”ํ•˜์ง€ ์•Š์€ ์ด์œ ๋Š”?
234 try catch ๋ธ”๋ก๊ณผ ์—๋Ÿฌ ๋ฐ”์šด๋”๋ฆฌ์˜ ์ฐจ์ด์ ์€?
235 react 16์—์„œ ์žกํžˆ์ง€ ์•Š๋Š” ์˜ค๋ฅ˜์˜ ๋™์ž‘์€?
236 ์—๋Ÿฌ ๋ฐ”์šด๋”๋ฆฌ์˜ ์ ์ ˆํ•œ ์œ„์น˜๋Š”?
237 ์—๋Ÿฌ ๋ฐ”์šด๋”๋ฆฌ์—์„œ ์ปดํฌ๋„ŒํŠธ ์Šคํƒ ์ถ”์ ์˜ ์žฅ์ ์€?
238 ํด๋ž˜์Šค ์ปดํฌ๋„ŒํŠธ์— ์ •์˜ํ•ด์•ผ ํ•˜๋Š” ๋ฉ”์„œ๋“œ๋Š” ๋ฌด์—‡์ธ๊ฐ€?
239 render ๋ฉ”์„œ๋“œ์˜ return ๊ฐ€๋Šฅํ•œ ํƒ€์ž…์€?
240 constructor์˜ ์ฃผ์š” ๋ชฉ์ ์€?
241 React ์ปดํฌ๋„ŒํŠธ์˜ ์ƒ์„ฑ์ž๋ฅผ ์ •์˜ํ•ด์•ผ ํ•˜๋‚˜?
242 default props๋ž€?
243 componentWillUnmount์—์„œ setState๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด ์•ˆ๋˜๋Š” ์ด์œ ๋Š”?
244 getDerivedStateFromError์˜ ๋ชฉ์ ์€?
245 ๋ฆฌ๋ Œ๋”๋งํ•  ๋•Œ ๋ฉ”์„œ๋“œ์˜ ์ˆœ์„œ๋Š”?
246 ์—๋Ÿฌ ํ•ธ๋“ค๋ง ์ค‘ ํ˜ธ์ถœ๋˜๋Š” ๋ฉ”์„œ๋“œ๋Š”?
247 displayName ํด๋ž˜์Šค ์†์„ฑ์˜ ๋ชฉ์ ์€?
248 react ์‘์šฉํ”„๋กœ๊ทธ๋žจ์˜ ๋ธŒ๋ผ์šฐ์ € ์ง€์›์€ ์–ด๋””๊นŒ์ง€์ธ๊ฐ€?
249 unmountComponentAtNode ๋ฉ”์„œ๋“œ์˜ ๋ชฉ์ ์€?
250 code-splitting์ด๋ž€?
251 strict mode์˜ ์žฅ์ ์€?
252 Keyed Fragments๋ž€?
253 React๋Š” ๋ชจ๋“  HTML ์†์„ฑ์„ ์ง€์›ํ•˜๋‚˜?
254 HOC์˜ ํ•œ๊ณ„๋Š”?
255 ๊ฐœ๋ฐœ์ž ๋„๊ตฌ์—์„œ forwardRefs๋ฅผ ๋””๋ฒ„๊น…ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
256 ์ปดํฌ๋„ŒํŠธ props์˜ ๊ธฐ๋ณธ๊ฐ’์€ true์ธ๊ฐ€?
257 NextJS๋Š” ๋ฌด์—‡์ด๋ฉฐ, ์ฃผ์š”ํ•œ ๊ธฐ๋Šฅ์€?
258 ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ๋ฅผ ์ปดํฌ๋„ŒํŠธ์— ์–ด๋–ป๊ฒŒ ์ „๋‹ฌํ•˜๋‚˜?
259 render ๋ฉ”์„œ๋“œ์—์„œ ํ™”์‚ดํ‘œ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹์€๊ฐ€?
260 ํ•จ์ˆ˜๊ฐ€ ์—ฌ๋Ÿฌ ๋ฒˆ ํ˜ธ์ถœ๋˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
261 JSX๊ฐ€ Injection ๊ณต๊ฒฉ์€ ๋ง‰๋Š” ๋ฐฉ๋ฒ•์€?
262 ๋ Œ๋”๋ง ๋œ ์š”์†Œ๋Š” ์–ด๋–ป๊ฒŒ ์—…๋ฐ์ดํŠธํ•˜๋‚˜?
263 props๊ฐ€ ์ฝ๊ธฐ ์ „์šฉ์ด์–ด์•ผ ํ•˜๋Š” ์ด์œ ๋Š”?
264 state updates๊ฐ€ ์–ด๋–ป๊ฒŒ ๋ณ‘ํ•ฉ๋˜๋‚˜?
265 ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ์— ์ธ์ˆ˜๋ฅผ ์–ด๋–ป๊ฒŒ ๋„˜๊ธฐ๋‚˜?
266 ์ปดํฌ๋„ŒํŠธ ๋ Œ๋”๋ง์„ ๋ง‰๋Š” ๋ฐฉ๋ฒ•์€?
267 index๋ฅผ ํ‚ค๋กœ ์•ˆ์ „ํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ์กฐ๊ฑด์€?
268 ํ‚ค๊ฐ€ ์ „์ฒด์—์„œ ๊ณ ์œ ํ•ด์•ผ ํ•˜๋‚˜?
269 Form ์ฒ˜๋ฆฌ์— ๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉ๋˜๋Š” ์„ ํƒ์ง€๋Š”?
270 redux form ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ณด๋‹ค formik์˜ ์žฅ์ ์€?
271 ์ƒ์†ํ•  ํ•„์š”๊ฐ€ ์—†๋Š” ์ด์œ ๋Š”?
272 react ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์›น ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‚˜?
273 dynamic import๋ž€?
274 loadable ์ปดํฌ๋„ŒํŠธ๋ž€?
275 suspense ์ปดํฌ๋„ŒํŠธ๋ž€?
276 ๋ผ์šฐํŠธ ๊ธฐ๋ฐ˜์˜ ์ฝ”๋“œ ์Šคํ”Œ๋ฆฌํŒ…์ด๋ž€?
277 context๋ฅผ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋Š”์ง€์— ๋Œ€ํ•œ ์˜ˆ์ œ
278 context์—์„œ ๊ธฐ๋ณธ๊ฐ’์˜ ๋ชฉ์ ์€?
279 contextType์€ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋‚˜?
280 consumer๋ž€?
281 context๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋™์•ˆ ์„ฑ๋Šฅ ๋ฌธ์ œ๋Š” ์–ด๋–ป๊ฒŒ ํ•ด๊ฒฐํ•˜๋‚˜?
282 HOC์—์„œ forward ref์˜ ๋ชฉ์ ์€?
283 ref๋Š” ๋ชจ๋“  ํ•จ์ˆ˜ ๋˜๋Š” ํด๋ž˜์Šค ์ปดํฌ๋„ŒํŠธ์—์„œ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•œ๊ฐ€?
284 forward ref๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋™์•ˆ ์ปดํฌ๋„ŒํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ถ”๊ฐ€๋กœ ๊ด€๋ฆฌํ•ด์•ผํ•˜๋Š” ์ด์œ ๋Š”?
285 ES6 ์—†์ด react ํด๋ž˜์Šค ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์€?
286 react์—์„œ JSX ์—†์ด ๊ฐ€๋Šฅํ•œ๊ฐ€?
287 diffing ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด๋ž€?
288 diffing ์•Œ๊ณ ๋ฆฌ์ฆ˜์— ์ ์šฉ๋˜๋Š” ๊ทœ์น™์€?
289 ์–ธ์ œ ref๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋‚˜?
290 prop์„ render prop์˜ ๋ Œ๋”๋ง์œผ๋กœ ์ง€์ •ํ•ด์•ผ ํ•˜๋‚˜?
291 ์ˆœ์ˆ˜ ์ปดํฌ๋„ŒํŠธ์™€ render props๋ฅผ ๊ฐ™์ด ์‚ฌ์šฉํ•˜๋ฉด ๋ฌธ์ œ๊ฐ€ ์žˆ๋‚˜?
292 How do you create HOC using render props?
293 windowing technique์ด๋ž€?
294 JSX์—์„œ ์ž˜๋ชป๋œ ๊ฐ’์€ ์–ด๋–ป๊ฒŒ ์ถœ๋ ฅํ•˜๋‚˜?
295 portals๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์‚ฌ๋ก€๋Š”?
296 ์ œ์–ด๋˜์ง€ ์•Š๋Š” ์ปดํฌ๋„ŒํŠธ์˜ ๊ธฐ๋ณธ๊ฐ’์„ ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
297 ๊ฐ€์žฅ ์ข‹์•„ํ•˜๋Š” React stack์€?
298 Real DOM๊ณผ Virtual DOM์˜ ์ฐจ์ด์ ์€?
299 react ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋ถ€ํŠธ์ŠคํŠธ๋žฉ์„ ์ถ”๊ฐ€ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
300 ํ”„๋ก ํŠธ์—”๋“œ ํ”„๋ ˆ์ž„์›Œํฌ๋กœ React๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฉ”์ธ ์›น์‚ฌ์ดํŠธ๋‚˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€?
301 React์—์„œ CSS In JS ๊ธฐ์ˆ ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ ์ข‹์€๊ฐ€?
302 ๋ชจ๋“  ํด๋ž˜์Šค ์ปดํฌ๋„ŒํŠธ๋ฅผ hook์œผ๋กœ ์ „ํ™˜ํ•ด์•ผํ•˜๋‚˜?
303 React hook์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ๋ฐฉ๋ฒ•์€?
304 Hook์€ ํด๋ž˜์Šค์˜ ๋ชจ๋“  ์‚ฌ์šฉ ์‚ฌ๋ก€๋ฅผ ์ปค๋ฒ„ํ•  ์ˆ˜ ์žˆ๋‚˜?
305 hook ์ง€์›์„ ์œ„ํ•œ ์•ˆ์ •์ ์ธ ๋ฆด๋ฆฌ์ฆˆ๋Š”?
306 useState์—์„œ๋Š” ์™œ destructuring์„ ์‚ฌ์šฉํ•˜๋‚˜?
307 hook์„ ๋„์ž…ํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋˜๋Š” ์†Œ์Šค๋Š”?
308 ์›น ์ปดํฌ๋„ŒํŠธ์˜ ๋ช…๋ นํ˜• API์— ์ ‘๊ทผํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
309 formik์ด๋ž€?
310 Redux์—์„œ ๋น„๋™๊ธฐ ํ˜ธ์ถœ์„ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ์ผ๋ฐ˜์ ์ธ ๋ฏธ๋“ค์›จ์–ด๋Š”?
311 ๋ธŒ๋ผ์šฐ์ €๊ฐ€ JSX ์ฝ”๋“œ๋ฅผ ์ดํ•ดํ•˜๋‚˜?
312 React์—์„œ ๋ฐ์ดํ„ฐ ํ๋ฆ„์— ๋Œ€ํ•ด ์„ค๋ช…ํ•˜์ž๋ฉด?
313 react scripts๋ž€?
314 create react app์˜ ๊ธฐ๋Šฅ์€?
315 renderToNodeStream ๋ฉ”์„œ๋“œ์˜ ๋ชฉ์ ์€?
316 MobX๋ž€?
317 Redux์™€ MobX์˜ ์ฐจ์ด์ ์€?
318 ReactJS๋ฅผ ๋ฐฐ์šฐ๊ธฐ ์ „์— ES6๋ฅผ ๋ฐฐ์›Œ์•ผํ•˜๋‚˜?
319 Concurrent Rendering์ด๋ž€?
320 What is the difference between async mode and concurrent mode?
321 react16.9์—์„œ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ urls๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‚˜?
322 hooks์—์„œ eslint ํ”Œ๋Ÿฌ๊ทธ์ธ์˜ ๋ชฉ์ ์€?
323 React์—์„œ ๋ช…๋ นํ˜•๊ณผ ์„ ์–ธํ˜•์˜ ์ฐจ์ด์ ์€
324 Reactjs์™€ ํ•จ๊ป˜ Typescript๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ์žฅ์ ?
325 Context API State Management ์‚ฌ์šฉ ์‹œ ํŽ˜์ด์ง€ ์ƒˆ๋กœ ๊ณ ์นจ์„ ํ•ด๋„ ์‚ฌ์šฉ์ž๊ฐ€ ์ธ์ฆ๋œ ์ƒํƒœ๋ฅผ ์œ ์ง€ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?
326 ์ƒˆ๋กœ์šด JSX transform์˜ ์žฅ์ ์€?
327 ์ƒˆ๋กœ์šด JSX transform๊ณผ ์˜ˆ์ „ transform์˜ ์ฐจ์ด์ ์€?
328 ์–ด๋–ป๊ฒŒ create-react-app๋ฅผ ์‚ฌ์šฉํ•ด์„œ redux scaffolding์„ ํ•˜๋‚˜?
329 React Server components๋ž€?
330 prop drilling ์ด๋ž€ ๋ฌด์—‡์ธ๊ฐ€?
331 What are the different ways to prevent state mutation?

Core React

  1. React๋ž€ ๋ฌด์—‡์ธ๊ฐ€?

    React๋Š” ๋‹จ์ผ ํŽ˜์ด์ง€ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์œผ๋กœ UI(user interface)๋ฅผ ๋งŒ๋“œ๋Š”๋ฐ ์‚ฌ์šฉ๋˜๋Š” ์˜คํ”ˆ-์†Œ์Šค ํ”„๋ก ํŠธ์—”๋“œ JavaScript ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋กœ ์›น๊ณผ ๋ชจ๋ฐ”์ผ ์•ฑ์—์„œ view layer๋ฅผ ๋‹ค๋ฃจ๋Š”๋ฐ ์‚ฌ์šฉ๋œ๋‹ค. React๋Š” Facebook์—์„œ ์†Œํ”„ํŠธ์›จ์–ด ์—”์ง€๋‹ˆ์–ด๋กœ ์žˆ๋Š” Jordan Walke๊ฐ€ ๋งŒ๋“ค์—ˆ๋‹ค. React๋Š” 2011๋…„ Facebook's News Feed, 2012๋…„ Instagram์—์„œ ์ฒ˜์Œ ์„ ๋ณด์˜€๋‹ค.

  2. React์˜ ์ฃผ์š” ํŠน์ง•์€?

    React์˜ ์ฃผ์š” ํŠน์ง•์€ :

    • ์‹ค์ œ๋”(RealDOM)์„ ์กฐ์ž‘ํ•˜๋Š” ๊ฒƒ์€ ๋น„์šฉ์ด ํฌ๋‹ค๋Š” ๊ฒƒ์„ ๊ณ ๋ คํ•˜์—ฌ ์‹ค์ œ๋” ๋Œ€์‹ ์— ๊ฐ€์ƒ๋”(VirtualDOM) ์„ ์‚ฌ์šฉํ•œ๋‹ค.
    • ์„œ๋ฒ„-์‚ฌ์ด๋“œ ๋ Œ๋”๋ง(server-side rendering) ๋ฅผ ์ง€์›ํ•œ๋‹ค.
    • ๋‹จ๋ฐฉํ–ฅ ๋ฐ์ดํ„ฐ ํ๋ฆ„ ๋˜๋Š” ๋ฐ์ดํ„ฐ ๋ฐ”์ธ๋”ฉ์„ ๋”ฐ๋ฅธ๋‹ค.
    • ํ™”๋ฉด ๊ฐœ๋ฐœ์„ ์œ„ํ•ด ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ(reusable)/๊ตฌ์„ฑ ๊ฐ€๋Šฅํ•œ(composable) UI ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
  3. JSX๋ž€ ๋ฌด์—‡์ธ๊ฐ€?

    JSX ๋Š” ECMAScript๋ฅผ ์œ„ํ•œ XML-์ฒ˜๋Ÿผ ์ƒ๊ธด ๊ตฌ๋ฌธ ํ™•์žฅ์ž(JavaScript XML ์˜ ์•ฝ์–ด)์ด๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ React.createElement() ํ•จ์ˆ˜๋ฅผ ์œ„ํ•œ syntactic sugar, JavaScript์˜ ํ‘œํ˜„๋ ฅ๊ณผ HTML๊ฐ™์€ ํ…œํ”Œ๋ฆฟ ๋ฌธ๋ฒ•์„ ์ œ๊ณตํ•œ๋‹ค.

    ์•„๋ž˜ ์˜ˆ์ œ์—์„œ <h1> ํƒœ๊ทธ ์•ˆ์˜ ํ…์ŠคํŠธ๋Š” render ํ•จ์ˆ˜์— JavaScript ํ•จ์ˆ˜๋กœ ๋ฐ˜ํ™˜๋œ๋‹ค.

    class App extends React.Component {
      render() {
        return(
          <div>
            <h1>{'Welcome to React world!'}</h1>
          </div>
        )
      }
    }
  4. Element์™€ Component์˜ ์ฐจ์ด์ ์€?

    Element ๋Š” DOM ๋…ธ๋“œ๋‚˜ ๋‹ค๋ฅธ ์ปดํฌ๋„ŒํŠธ๋“ค ๊ด€์ ์—์„œ ํ™”๋ฉด์— ๋ณด์ด๊ธฐ ์›ํ•˜๋Š” ๊ฑธ ๋ฌ˜์‚ฌํ•œ ์ผ๋ฐ˜ ๊ฐ์ฒด์ด๋‹ค. Elements ๋Š” props์— ์žˆ๋Š” ๋‹ค๋ฅธ Elements ๋ฅผ ํฌํ•จํ•  ์ˆ˜ ์žˆ๋‹ค. React element๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒƒ์€ ์ €๋ ดํ•˜๋‹ค. ์ผ๋‹จ element๊ฐ€ ๋งŒ๋“ค์–ด์ง€๋ฉด ์ ˆ๋Œ€ ๋ณ€๊ฒฝ๋˜์ง€ ์•Š๋Š”๋‹ค.

    React Element ๊ฐ์ฒด ํ‘œํ˜„์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. :

    const element = React.createElement(
      'div',
      {id: 'login-btn'},
      'Login'
    )

    ์œ„์˜ React.createElement() ํ•จ์ˆ˜๋Š” ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. :

    {
      type: 'div',
      props: {
        children: 'Login',
        id: 'login-btn'
      }
    }
    

    ๋งˆ์ง€๋ง‰์œผ๋กœ ReactDOM.render() ๋ฅผ ์‚ฌ์šฉํ•ด์„œ DOM์œผ๋กœ ๋ Œ๋”๋งํ•œ๋‹ค. :

    <div id='login-btn'>Login</div>

    ๋ฐ˜๋ฉด์— component ๋Š” ์—ฌ๋Ÿฌ ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์œผ๋กœ ์„ ์–ธ๋  ์ˆ˜ ์žˆ๋‹ค. render() ๋ฉ”์†Œ๋“œ๋ฅผ ํฌํ•จํ•œ ํด๋ž˜์Šค๊ฐ€ ๋  ์ˆ˜ ์žˆ๋‹ค. ๋˜๋Š” ๋‹จ์ˆœํ•˜๊ฒŒ ํ•จ์ˆ˜๋กœ ์ •์˜๋  ์ˆ˜ ์žˆ๋‹ค. ๋‘ ๊ฒฝ์šฐ ๋ชจ๋‘, ์ž…๋ ฅ์œผ๋กœ props๋ฅผ ๊ฐ€์ ธ์˜ค๊ณ , ์ถœ๋ ฅ์œผ๋กœ JSX tree๋ฅผ returnํ•œ๋‹ค.

    const Button = ({ onLogin }) =>
      <div id={'login-btn'} onClick={onLogin}>Login</div>

    JSX๋Š” React.createElement() ํ•จ์ˆ˜ ํŠธ๋ฆฌ๋กœ ๋ณ€ํ™˜๋œ๋‹ค. :

    const Button = ({ onLogin }) => React.createElement(
      'div',
      { id: 'login-btn', onClick: onLogin },
      'Login'
    )
  5. React์—์„œ components๋Š” ์–ด๋–ป๊ฒŒ ๋งŒ๋“œ๋‚˜?

    ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์€ 2๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค.

    1. Function Components: ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋งŒ๋“œ๋Š” ๊ฐ€์žฅ ๊ฐ„๋‹จํ•œ ๋ฐฉ๋ฒ•์ด๋‹ค. ์ˆœ์ˆ˜ JavaScript functions ๋กœ ์ฒซ๋ฒˆ์งธ ์ธ์ž๋กœ๋Š” props ๊ฐ์ฒด๋ฅผ ๋ฐ›๊ณ  React elements๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. :

      function Greeting({ message }) {
        return <h1>{`Hello, ${message}`}</h1>โ€จ
      }
    2. Class Components: ES6์˜ class๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค. ์œ„์˜ ํ•จ์ˆ˜๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ž‘์„ฑ๋  ์ˆ˜ ์žˆ๋‹ค. :

      class Greeting extends React.Component {
        render() {
          return <h1>{`Hello, ${this.props.message}`}</h1>
        }
      }
  6. ์–ธ์ œ Function Component ๋Œ€์‹ ์— Class Component๋ฅผ ์‚ฌ์šฉํ•˜๋‚˜?

    ๋งŒ์•ฝ, ์ปดํฌ๋„ŒํŠธ๊ฐ€ state๋‚˜ lifecycle methods๊ฐ€ ํ•„์š”ํ•˜๋‹ค๋ฉด class ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์•„๋‹ˆ๋ผ๋ฉด function ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

  7. Pure Components๋ž€ ๋ฌด์—‡์ธ๊ฐ€?

    React.PureComponent ๋Š” shouldComponentUpdate() ๋ฉ”์„œ๋“œ๋ฅผ ์ œ์–ดํ•˜๋Š” ๊ฒƒ์„ ์ œ์™ธํ•˜๋ฉด *React.Component*์™€ ๋‹ค๋ฅด์ง€ ์•Š๋‹ค. props๋‚˜ state๊ฐ€ ๋ณ€๊ฒฝ๋˜๋ฉด PureComponent ๋Š” props์™€ state ์— ๋Œ€ํ•ด์„œ ์–•์€ ๋น„๊ต๋ฅผ ์ˆ˜ํ–‰ํ•œ๋‹ค. ๋ฐ˜๋ฉด์— Component ๋Š” ํ˜„์žฌ์˜ props์™€ state์— ๋Œ€ํ•ด ๋น„๊ต๋ฅผ ํ•˜์ง€ ์•Š๋Š”๋‹ค. ๋”ฐ๋ผ์„œ shouldComponentUpdate๊ฐ€ ํ˜ธ์ถœ๋  ๋•Œ๋งˆ๋‹ค ๋ฆฌ๋ Œ๋”๋ง๋œ๋‹ค.

  8. React์—์„œ state๋Š” ๋ฌด์—‡์ธ๊ฐ€?

    ์ปดํฌ๋„ŒํŠธ์˜ State๋Š” ์ปดํฌ๋„ŒํŠธ์˜ ๋ณ€๊ฒฝ ๋  ์ˆ˜ ์žˆ๋Š” ์ •๋ณด๋ฅผ ๋ณด์œ ํ•˜๋Š” ๊ฐ์ฒด์ด๋‹ค. ๊ฐ€๋Šฅํ•œ ํ•œ ๊ฐ„๋‹จํ•˜๊ฒŒ ์ƒํƒœ๋ฅผ ๋งŒ๋“ค๊ณ  stateful ์ปดํฌ๋„ŒํŠธ์˜ ์ˆ˜๋ฅผ ์ตœ์†Œํ™”ํ•ด์•ผ ํ•œ๋‹ค. message state๋ฅผ ๊ฐ€์ง„ User ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž.

    class User extends React.Component {
      constructor(props) {
        super(props)
    
        this.state = {
          message: 'Welcome to React world'
        }
      }
    
      render() {
        return (
          <div>
            <h1>{this.state.message}</h1>
          </div>
        )
      }
    }

    state

    state๋Š” props์™€ ๋น„์Šทํ•˜์ง€๋งŒ private ํ•˜๋ฉฐ ์ปดํฌ๋„ŒํŠธ์— ์˜ํ•ด ์ œ์–ด๋œ๋‹ค. ์ฆ‰, ์ƒํƒœ๋Š” ์ด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๊ฑฐ๋‚˜ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋Š” ์ปดํฌ๋„ŒํŠธ ์ด์™ธ์—๋Š” ์ ‘๊ทผํ•  ์ˆ˜ ์—†๋‹ค.

  9. React์—์„œ props๋Š” ๋ฌด์—‡์ธ๊ฐ€?

    Props๋Š” ์ปดํฌ๋„ŒํŠธ์— ๋Œ€ํ•œ ์ž…๋ ฅ์ด๋‹ค. Props๋Š” HTML ํƒœ๊ทธ ์†์„ฑ๊ณผ ๊ฐ™์€ ์ž‘๋ช… ๊ทœ์น™์„ ์‚ฌ์šฉํ•˜์—ฌ ์ปดํฌ๋„ŒํŠธ์— ์ „๋‹ฌ๋˜๋Š” ๋‹จ์ผ ๊ฐ’ ํ˜น์€ ๊ฐ์ฒด๋‹ค. props๋Š” ๋ถ€๋ชจ ์ปดํฌ๋„ŒํŠธ์—์„œ ์ž์‹ ์ปดํฌ๋„ŒํŠธ๋กœ ์ „๋‹ฌ๋œ๋‹ค.

    React์—์„œ props์˜ ์ฃผ๋ชฉ์ ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ปดํฌ๋„ŒํŠธ์˜ ๊ธฐ๋Šฅ๋“ค์„ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

    1. ์ปค์Šคํ…€ ๋ฐ์ดํ„ฐ๋ฅผ ์ปดํฌ๋„ŒํŠธ๋กœ ์ „๋‹ฌํ•œ๋‹ค.
    2. state์˜ ๋ณ€๊ฒฝ์„ ์ผ์œผํ‚จ๋‹ค.
    3. ์ปดํฌ๋„ŒํŠธ์˜ render() ๋ฉ”์„œ๋“œ ๋‚ด์—์„œ this.props.reactProp ๋ฅผ ํ†ตํ•ด ์‚ฌ์šฉํ•œ๋‹ค.

    ์˜ˆ๋ฅผ ๋“ค์–ด reactProp ์š”์†Œ๋ฅผ ๊ฐ€์ง„ ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž.

    <Element reactProp={'1'} />

    ์ด reactProp (๋˜๋Š” ์—ฌ๋Ÿฌ๋ถ„์ด ๋งŒ๋“  ๊ฒƒ์€ ๋ฌด์—‡์ด๋“ ) React๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ƒ์„ฑ๋œ ๋ชจ๋“  ์ปดํฌ๋„ŒํŠธ์— ์›๋ž˜ ์กด์žฌํ•˜๋Š” props ๊ฐ์ฒด์˜ ์†์„ฑ์ด ๋œ๋‹ค.

    props.reactProp
    
  10. state์™€ prop์˜ ์ฐจ์ด์ ์€?

    props์™€ state๋Š” ๋ชจ๋‘ ์ˆœ์ˆ˜ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๊ฐ์ฒด๋‹ค. ๋‘˜ ๋‹ค ๋ Œ๋”๋ง ๊ฒฐ๊ณผ์— ์˜ํ–ฅ์„ ์ฃผ๋Š” ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์ง€๋งŒ, ์ปดํฌ๋„ŒํŠธ์™€ ๊ด€๋ จ๋œ ๊ธฐ๋Šฅ ๋ฉด์—์„œ ๋‹ค๋ฅด๋‹ค. props๋Š” ํ•จ์ˆ˜์˜ ๋งค๊ฐœ๋ณ€์ˆ˜์™€ ๋น„์Šทํ•˜๊ฒŒ ์ปดํฌ๋„ŒํŠธ๋กœ ์ „๋‹ฌ๋˜๋Š” ๋ฐ˜๋ฉด, state๋Š” ํ•จ์ˆ˜ ๋‚ด์—์„œ ์„ ์–ธ๋œ ๋ณ€์ˆ˜์™€ ์œ ์‚ฌํ•˜๊ฒŒ ์ปดํฌ๋„ŒํŠธ ๋‚ด์—์„œ ๊ด€๋ฆฌ๋œ๋‹ค.

  11. ์™œ state๋ฅผ ์ง์ ‘ updateํ•˜๋ฉด ์•ˆ๋˜๋‚˜?

    ํ˜น์‹œ๋ผ๋„ state๋ฅผ ์ง์ ‘์ ์œผ๋กœ ์—…๋ฐ์ดํŠธ๋ฅผ ํ•˜๊ฒŒ ๋˜๋ฉด ์ปดํฌ๋„ŒํŠธ๋Š” re-render๋ฅผ ํ•˜์ง€ ์•Š๋Š”๋‹ค.

    //Wrong
    this.state.message = 'Hello world'

    ๋Œ€์‹ ์— setState() ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ์ด ๋ฉ”์†Œ๋“œ๋Š” ์ปดํฌ๋„ŒํŠธ์˜ state ๊ฐ์ฒด์— ๋Œ€ํ•œ ์—…๋ฐ์ดํŠธ๋ฅผ ์˜ˆ์•ฝํ•œ๋‹ค. state๊ฐ€ ๋ฐ”๋€Œ๊ฒŒ ๋˜๋ฉด, ์ปดํฌ๋„ŒํŠธ๋Š” re-rendering์œผ๋กœ ์‘๋‹ต์„ ํ•œ๋‹ค.

    //Correct
    this.setState({ message: 'Hello World' })

    Note: constructor์—์„œ๋‚˜ ์ตœ์‹  Javascript์˜ class ์„ ์–ธ ๊ตฌ๋ฌธ์„ ์‚ฌ์šฉํ•ด์„œ state ๊ฐ์ฒด์— ์ง์ ‘ ํ• ๋‹นํ•  ์ˆ˜ ์žˆ๋‹ค.

  12. setState()์˜ argument๋กœ callback ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ๋Š”?

    callback ํ•จ์ˆ˜๋Š” setState๊ฐ€ ๋๋‚˜๊ณ  ์ปดํฌ๋„ŒํŠธ๊ฐ€ render ๋˜์—ˆ์„ ๋•Œ ์ž‘๋™ํ•œ๋‹ค. setState()๋Š” ๋น„๋™๊ธฐ์‹์ด์—ฌ์„œ callback ํ•จ์ˆ˜๋Š” ๋ชจ๋“  ์ž‘์—… ํ›„ ์‚ฌ์šฉ๋œ๋‹ค.

    Note: ์ด callback ํ•จ์ˆ˜๋ณด๋‹ค๋Š” lifecycle ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.

    setState({ name: 'John' }, () => console.log('The name has updated and component re-rendered'))
  13. HTML๊ณผ React์˜ event handling์˜ ์ฐจ์ด์ ์€?

    1. HTML์—์„œ, ์ด๋ฒคํŠธ ์ด๋ฆ„์€ ์†Œ๋ฌธ์ž์—ฌ์•ผ ํ•œ๋‹ค:
    <button onclick='activateLasers()'>

    ๋ฐ˜๋ฉด์— React์—์„œ๋Š” camelCase ๊ทœ์น™์„ ๋”ฐ๋ฅธ๋‹ค:

    <button onClick={activateLasers}>
    1. HTML์—์„œ, ๊ธฐ๋ณธ ๋™์ž‘ ๋ฐฉ์ง€๋ฅผ ์œ„ํ•ด false๋ฅผ ๋ฐ˜ํ™˜ํ•  ์ˆ˜ ์žˆ๋‹ค:
    <a href='#' onclick='console.log("The link was clicked."); return false;' />

    ๋ฐ˜๋ฉด์— React์—์„œ๋Š” preventDefault()๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ํ˜ธ์ถœํ•ด์•ผ ํ•œ๋‹ค:

    function handleClick(event) {
      event.preventDefault()
      console.log('The link was clicked.')
    }
  14. ์–ด๋–ป๊ฒŒ JSX ์ฝœ๋ฐฑ์—์„œ ๋ฉ”์„œ๋“œ์™€ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ๋ฅผ ๋ฐ”์ธ๋“œํ•˜๋‚˜?

    ์ด๋ฅผ ์ด๋ฃจ๊ธฐ ์œ„ํ•œ 3๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค.

    1. ์ƒ์„ฑ์ž์—์„œ ๋ฐ”์ธ๋”ฉ: JavaScript ํด๋ž˜์Šค์—์„œ, ๋ฉ”์„œ๋“œ๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ฐ”์ธ๋”ฉ ๋˜์ง€ ์•Š๋Š”๋‹ค. ํด๋ž˜์Šค ๋ฉ”์„œ๋“œ๋กœ ์ •์˜๋œ React ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ์—๊ฒŒ์„œ๋„ ๋˜‘๊ฐ™์€ ๋ฌธ์ œ๊ฐ€ ์ ์šฉ๋œ๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ ์šฐ๋ฆฌ๋Š” ์ƒ์„ฑ์ž ์•ˆ์—์„œ ๋ฐ”์ธ๋“œ๋ฅผ ํ•œ๋‹ค.
    class Component extends React.Componenet {
      constructor(props) {
        super(props)
        this.handleClick = this.handleClick.bind(this)
      }
    
      handleClick() {
        // ...
      }
    }
    1. Public ํด๋ž˜์Šค ํ•„๋“œ ๊ตฌ๋ฌธ: ๋ฐ”์ธ๋“œ ์ ‘๊ทผ๋ฒ•์ด ์‹ซ๋‹ค๋ฉด ์ฝœ๋ฐฑ์„ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ๋ฐ”์ธ๋“œํ•˜๊ธฐ ์œ„ํ•ด public ํด๋ž˜์Šค ํ•„๋“œ ๊ตฌ๋ฌธ ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
    handleClick = () => {
      console.log('this is:', this)
    }
    <button onClick={this.handleClick}>
      {'Click me'}
    </button>
    1. ์ฝœ๋ฐฑ ์•ˆ์—์„œ ํ™”์‚ดํ‘œ ํ•จ์ˆ˜: ์ฝœ๋ฐฑ ์•ˆ์—์„œ ์ง์ ‘ ํ™”์‚ดํ‘œ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
    <button onClick={(event) => this.handleClick(event)}>
      {'Click me'}
    </button>

    Note: ์ฝœ๋ฐฑ์ด ์ž์‹ ์ปดํฌ๋„ŒํŠธ์— prop์œผ๋กœ ์ „๋‹ฌ์ด ๋˜๋ฉด, ํ•ด๋‹น ์ปดํฌ๋„ŒํŠธ๋Š” ์ถ”๊ฐ€ ๋ฆฌ๋ Œ๋”๋ง์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด ๊ฒฝ์šฐ์—, ์„ฑ๋Šฅ์„ ๊ณ ๋ คํ•˜์—ฌ .bind() ๋˜๋Š” public ํด๋ž˜์Šค ํ•„๋“œ ๊ตฌ๋ฌธ ์ ‘๊ทผ๋ฒ•์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.

  15. ์–ด๋–ป๊ฒŒ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ๋‚˜ ์ฝœ๋ฐฑ์— ๋งค๊ฐœ ๋ณ€์ˆ˜๋ฅผ ์ „๋‹ฌํ•˜๋‚˜?

    ํ™”์‚ดํ‘œ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ๋ฅผ ๊ฐ์‹ธ๊ณ  ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋‹ค.

    <button onClick={() => this.handleClick(id)} />

    .bind๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๊ฒƒ๊ณผ ๋™์ผํ•˜๋‹ค:

    <button onClick={this.handleClick.bind(this, id)} />

    Apart from these two approaches, you can also pass arguments to a function which is defined as array function

    <button onClick={this.handleClick(id)} />
    handleClick = (id) => () => {
        console.log("Hello, your ticket number is", id)
    };
  16. React์— SyntheticEvent๋ž€ ๋ฌด์—‡์ธ๊ฐ€?

    SyntheticEvent๋Š” ๋ธŒ๋ผ์šฐ์ €์˜ ๊ธฐ๋ณธ ์ด๋ฒคํŠธ๋ฅผ ๊ฐ์‹ผ cross-browser wrapper์ด๋‹ค. stopPropagation()๊ณผ preventDefault()๋ฅผ ํฌํ•จํ•œ API๋กœ, ๋ธŒ๋ผ์šฐ์ €์˜ ๊ธฐ๋ณธ ์ด๋ฒคํŠธ์™€ ๋™์ผํ•˜์ง€๋งŒ, ๋ชจ๋“  ๋ธŒ๋ผ์šฐ์ €์—์„œ ๋™์ผํ•˜๊ฒŒ ์ž‘๋™ํ•œ๋‹ค๋Š” ์ ์ด ๋‹ค๋ฅด๋‹ค.

  17. ์ธ๋ผ์ธ ์กฐ๊ฑด ํ‘œํ˜„์‹์ด๋ž€?

    JS์—์„œ ์กฐ๊ฑด๋ถ€๋กœ ์‹์„ ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•ด์„œ if ๋ฌธ ์ด๋‚˜ ์‚ผํ•ญ ํ‘œํ˜„์‹ ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด๋Ÿฌํ•œ ์ ‘๊ทผ๋ฒ• ์™ธ์—๋„, JS ๋…ผ๋ฆฌ์—ฐ์‚ฐ์ž์ธ &&๊ฐ€ ์žˆ๋Š” ์ค‘๊ด„ํ˜ธ๋กœ ๊ฐ์‹ผ ํ‘œํ˜„์‹์„ JSX์— ํฌํ•จํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

    <h1>Hello!</h1>
    {
        messages.length > 0 && !isLogin?
          <h2>
              You have {messages.length} unread messages.
          </h2>
          :
          <h2>
              You don't have unread messages.
          </h2>
    }
  18. "key" props๋Š” ๋ฌด์—‡์ด๋ฉฐ elements์˜ ๋ฐฐ์—ด์—์„œ ์‚ฌ์šฉํ•˜๋ฉด ์ด์ ์ด ๋ฌด์—‡์ธ๊ฐ€?

    key๋Š” elements ๋ฐฐ์—ด์„ ๋งŒ๋“ค ๋•Œ ํฌํ•จ์‹œ์ผœ์•ผ ํ•˜๋Š” ํŠน์ˆ˜ ๋ฌธ์ž์—ด ์†์„ฑ์ด๋‹ค. Keys๋Š” React๊ฐ€ ๋ณ€๊ฒฝ, ์ถ”๊ฐ€, ์ œ๊ฑฐ๋œ ํ•ญ๋ชฉ์„ ์‹๋ณ„ํ•˜๋Š” ๋ฐ ๋„์›€์„ ์ค€๋‹ค.

    ์šฐ๋ฆฌ๋Š” ๋Œ€๊ฐœ ๋ฐ์ดํ„ฐ์—์„œ ID๋ฅผ keys๋กœ ์‚ฌ์šฉํ•œ๋‹ค.

    const todoItems = todos.map((todo) =>
      <li key={todo.id}>
        {todo.text}
      </li>
    )

    ๋ Œ๋”๋ง๋œ ํ•ญ๋ชฉ ์ค‘ ์•ˆ์ •์ ์ธ ID๊ฐ€ ์—†์„ ๋•Œ, ๋งˆ์ง€๋ง‰ ์ˆ˜๋‹จ์œผ๋กœ ํ•ญ๋ชฉ์˜ index๋ฅผ key๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

    const todoItems = todos.map((todo, index) =>
      <li key={index}>
        {todo.text}
      </li>
    )

    Note:

    1. ํ•ญ๋ชฉ์˜ ์ˆœ์„œ๊ฐ€ ๋ณ€๊ฒฝ๋  ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ index๋ฅผ keys๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ ์ถ”์ฒœํ•˜์ง€ ์•Š๋Š”๋‹ค. ์ด๋Š” ์„ฑ๋Šฅ ์ €ํ•˜์™€ ์ปดํฌ๋„ŒํŠธ state์— ๋ฌธ์ œ๋ฅผ ๋ฐœ์ƒ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค.
    2. ๋ฆฌ์ŠคํŠธ ํ•ญ๋ชฉ์„ ๋ณ„๋„์˜ ์ปดํฌ๋„ŒํŠธ๋กœ ์ถ”์ถœํ•˜๋Š” ๊ฒฝ์šฐ li ํƒœ๊ทธ ๋Œ€์‹ ์— ๋ฆฌ์ŠคํŠธ ์ปดํฌ๋„ŒํŠธ์— keys๋ฅผ ์ ์šฉํ•ด๋ผ.
    3. ๋ฆฌ์ŠคํŠธ ํ•ญ๋ชฉ์— key prop๊ฐ€ ์—†์œผ๋ฉด console์— ๊ฒฝ๊ณ  ๋ฉ”์‹œ์ง€๊ฐ€ ํ‘œ์‹œ๋  ๊ฒƒ์ด๋‹ค.
  19. refs๋Š” ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉ๋˜๋Š”๊ฐ€?

    ref๋Š” ์—˜๋ฆฌ๋จผํŠธ์— ๋Œ€ํ•œ ์ฐธ์กฐ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋œ๋‹ค. ๋Œ€๋ถ€๋ถ„์˜ ๊ฒฝ์šฐ์—์„œ ํ”ผํ•˜๋Š” ๊ฒƒ์ด ์ข‹์ง€๋งŒ, DOM ์—˜๋ฆฌ๋จผํŠธ๋‚˜ ์ปดํฌ๋„ŒํŠธ์˜ ์ธ์Šคํ„ด์Šค์— ์ง์ ‘ ์ ‘๊ทผํ•˜๋Š” ๊ฒฝ์šฐ ์œ ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

  20. refs๋Š” ์–ด๋–ป๊ฒŒ ์ƒ์„ฑํ•˜๋Š”๊ฐ€?

    refs๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์—๋Š” 2๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค.

    1. ๋‹ค์Œ์€ ์ตœ๊ทผ์— ์ถ”๊ฐ€๋œ ๋ฐฉ๋ฒ•์ด๋‹ค. Refs๋Š” React.createRef()๋ฉ”์„œ๋“œ๋ฅผ ํ†ตํ•ด ์ƒ์„ฑ๋˜๋ฉฐ ref ์†์„ฑ์„ ํ†ตํ•ด React ์—˜๋ฆฌ๋จผํŠธ์— ์ ์šฉ๋œ๋‹ค. ์—˜๋ฆฌ๋จผํŠธ ์ „์ฒด์—์„œ refs๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ์ƒ์„ฑ์ž ๋‚ด์˜ ์ธ์Šคํ„ด์Šค ์†์„ฑ์— ref๋ฅผ ํ• ๋‹นํ•˜๋ฉด ๋œ๋‹ค.
    class MyComponent extends React.Component {
      constructor(props) {
        super(props)
        this.myRef = React.createRef()
      }
      render() {
        return <div ref={this.myRef} />
      }
    }
    1. React ๋ฒ„์ „์— ๊ด€๊ณ„์—†์ด ref ์ฝœ๋ฐฑ ์ ‘๊ทผ๋ฒ•์„ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๊ฒ€์ƒ‰์ฐฝ ์ปดํฌ๋„ŒํŠธ์˜ ์ž…๋ ฅ ์—˜๋ฆฌ๋จผํŠธ์—์„œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ ‘๊ทผํ•œ๋‹ค.
    class SearchBar extends Component {
       constructor(props) {
          super(props);
          this.txtSearch = null;
          this.state = { term: '' };
          this.setInputSearchRef = e => {
             this.txtSearch = e;
          }
       }
       onInputChange(event) {
          this.setState({ term: this.txtSearch.value });
       }
       render() {
          return (
             <input
                value={this.state.term}
                onChange={this.onInputChange.bind(this)}
                ref={this.setInputSearchRef} />
          );
       }
    }

    ํด๋กœ์ €(closures) ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ•จ์ˆ˜ํ˜• ์ปดํฌ๋„ŒํŠธ์—์„œ refs๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ๋‹ค. ์ฐธ๊ณ : ๊ถŒ์žฅํ•˜์ง„ ์•Š์ง€๋งŒ, ์ธ๋ผ์ธ ref ์ฝœ๋ฐฑ์„ ์ด์šฉํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

  21. forward refs๋Š” ๋ฌด์—‡์ธ๊ฐ€?

    Ref ์ „๋‹ฌ(Ref forwarding) ํŠน์ • ์ปดํฌ๋„ŒํŠธ์—์„œ ref๋ฅผ ๋ฐ›์•„ ์ž์‹์—๊ฒŒ ์ „๋‹ฌํ•˜๋Š” ๊ธฐ๋Šฅ์ด๋‹ค.

    const ButtonElement = React.forwardRef((props, ref) => (
      <button ref={ref} className="CustomButton">
        {props.children}
      </button>
    ));
    
    // Create ref to the DOM button:
    const ref = React.createRef();
    <ButtonElement ref={ref}>{'Forward Ref'}</ButtonElement>
  22. callback refs ๋ฐ findDOMNode()์—์„œ ์„ ํ˜ธ๋˜๋Š” ์˜ต์…˜์€?

    findDOMNode() API ์œ„์— callback refs๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค. findDOMNode()์ด ์ถ”ํ›„ React์—์„œ์˜ ๊ฐœ์„  ์‚ฌํ•ญ์„ ๋ฐฉํ•ดํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

    findDOMNode๋ฅผ ์‚ฌ์šฉํ•˜๋Š” legacy ์ ‘๊ทผ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

    class MyComponent extends Component {
      componentDidMount() {
        findDOMNode(this).scrollIntoView()
      }
    
      render() {
        return <div />
      }
    }

    ๊ถŒ์žฅ๋˜๋Š” ์ ‘๊ทผ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

    class MyComponent extends Component {
      constructor(props){
        super(props);
        this.node = createRef();
      }
      componentDidMount() {
        this.node.current.scrollIntoView();
      }
    
      render() {
        return <div ref={this.node} />
      }
    }
  23. String Refs๊ฐ€ ์™œ legacy์ธ๊ฐ€?

    React๋ฅผ ์‚ฌ์šฉํ•ด๋ณด๊ธฐ ์ „์ด๋ผ๋ฉด, ์˜ˆ์ „ API์—์„œ ref={'textInput'}๊ณผ ๊ฐ™์€ ref ์†์„ฑ์ด ๋ฌธ์ž์—ด์ธ ๊ฒƒ๊ณผ DOM node๊ฐ€ this.refs.textInput๊ณผ ๊ฐ™์ด ์•ก์„ธ์Šค ๋˜๋Š” ๊ฒƒ์— ์ต์ˆ™ํ•  ๊ฒƒ์ด๋‹ค. String Refs์— ๋ฌธ์ œ๊ฐ€ ์žˆ์–ด, legacy๋กœ ๊ฐ„์ฃผํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ธฐ๋ฅผ ๋ฐ”๋ž€๋‹ค. String Refs๋Š” React v16์— ์ œ๊ฑฐ๋˜์—ˆ๋‹ค.

    1. React๊ฐ€ ํ˜„์žฌ ์‹คํ–‰ ์ค‘์ธ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ถ”์ ํ•˜๋„๋ก ๊ฐ•์ œ๋œ๋‹ค. ์ด๋Š” react ๋ชจ๋“ˆ์„ stateful ํ•˜๊ฒŒ ๋งŒ๋“ค๊ณ , react ๋ชจ๋“ˆ์ด ๋ฒˆ๋“ค์— ๋ณต์ œ๋  ๋•Œ ์ด์ƒํ•œ ์˜ค๋ฅ˜๋ฅผ ์œ ๋ฐœํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฌธ์ œ๊ฐ€ ๋œ๋‹ค.
    2. composable ํ•˜์ง€ ์•Š๋‹ค. โ€” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์ „๋‹ฌ๋œ ์ž์‹์— ref๋ฅผ ๋„ฃ์œผ๋ฉด, ์‚ฌ์šฉ์ž๋Š” ๋‹ค๋ฅธ ref๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์—†๋‹ค. Callback ref๋Š” ์™„๋ฒฝํ•˜๊ฒŒ ๊ตฌ์„ฑ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
    3. Flow์™€ ๊ฐ™์€ ์ •์  ๋ถ„์„์—์„œ๋Š” ์ž‘๋™ํ•˜์ง€ ์•Š๋Š”๋‹ค. Flow๋Š” ํ”„๋ ˆ์ž„์›Œํฌ๊ฐ€ String Refs๋ฅผ this.refs์— ํ‘œ์‹œํ•˜๋„๋ก ํ•˜๋Š” ๋งˆ๋ฒ•๊ณผ ๊ทธ๊ฒƒ์˜ ํƒ€์ž…(๋‹ค๋ฅผ ์ˆ˜ ์žˆ์Œ)์„ ์ถ”์ธกํ•  ์ˆ˜ ์—†๋‹ค. Callback ref๋Š” ์ •์  ๋ถ„์„์— ์นœ์ˆ™ํ•ฉ๋‹ˆ๋‹ค..
    4. ๋Œ€๋ถ€๋ถ„์˜ ์‚ฌ๋žŒ์ด ์ƒ๊ฐํ•˜๋Š” "render callback" ํŒจํ„ด์œผ๋กœ ์ž‘๋™ํ•˜์ง€ ์•Š๋Š”๋‹ค. (์˜ˆ). <DataGrid renderRow={this.renderRow} />)
      class MyComponent extends Component {
        renderRow = (index) => {
          // This won't work. Ref will get attached to DataTable rather than MyComponent:
          return <input ref={'input-' + index} />;
      
          // This would work though! Callback refs are awesome.
          return <input ref={input => this['input-' + index] = input} />;
        }
      
        render() {
          return <DataTable data={this.props.data} renderRow={this.renderRow} />
        }
      }
  24. Virtual DOM์ด๋ž€?

    Virtual DOM (VDOM)๋Š” ์‹ค์ œ DOM์˜ ์ธ-๋ฉ”๋ชจ๋ฆฌ ํ‘œํ˜„์ด๋‹ค. UI ํ‘œํ˜„์€ ๋ฉ”๋ชจ๋ฆฌ์— ์œ ์ง€๋˜๊ณ  "์‹ค์ œ" DOM๊ณผ ๋™๊ธฐํ™”๋œ๋‹ค. ์ด๋Š” ๋ Œ๋” ํ•จ์ˆ˜์˜ ํ˜ธ์ถœ๊ณผ ํ™”๋ฉด์ƒ elements๋ฅผ ํ‘œํ˜„ํ•˜๋Š” ์‚ฌ์ด์— ๋ฐœ์ƒํ•˜๋Š” ๋‹จ๊ณ„์ด๋‹ค. ์ด ์ „์ฒด ํ”„๋กœ์„ธ์Šค๋Š” ์กฐ์ • ์ด๋ผ๊ณ  ํ•œ๋‹ค.

  25. Virtual DOM์€ ์–ด๋–ป๊ฒŒ ์ž‘๋™ํ•˜๋‚˜?

    Virtual DOM๋Š” ์„ธ ๊ฐ€์ง€ ๊ฐ„๋‹จํ•œ ๋‹จ๊ณ„๋กœ ์ž‘๋™ํ•œ๋‹ค.

    1. ๊ธฐ๋ณธ ๋ฐ์ดํ„ฐ๊ฐ€ ๋ณ€๊ฒฝ๋  ๋•Œ๋งˆ๋‹ค, ์ „์ฒด UI๋Š” Virtual DOM ํ‘œํ˜„์œผ๋กœ ๋ฆฌ๋ Œ๋”๋ง ๋œ๋‹ค. vdom

    2. ์ด์ „ DOM ํ‘œํ˜„๊ณผ ์ƒˆ๋กœ์šด ํ‘œํ˜„ ์‚ฌ์ด์˜ ์ฐจ์ด๋ฅผ ๊ณ„์‚ฐํ•œ๋‹ค. vdom2

    3. ๊ณ„์‚ฐ์ด ์™„๋ฃŒ๋˜๋ฉด, ์‹ค์ œ DOM์€ ์‹ค์ œ๋กœ ๋ณ€๊ฒฝ๋œ ๊ฒƒ๋งŒ ์—…๋ฐ์ดํŠธํ•  ๊ฒƒ์ด๋‹ค. vdom3

  26. Shadow DOM๊ณผ Virtual DOM์˜ ์ฐจ์ด์ 

    Shadow DOM ์ฃผ๋กœ ์›น ์ปดํฌ๋„ŒํŠธ์—์„œ ๋ณ€์ˆ˜์™€ CSS์˜ ๋ฒ”์œ„ ์ง€์ •์„ ์œ„ํ•ด ๋””์ž์ธ๋œ ๋ธŒ๋ผ์šฐ์ € ๊ธฐ์ˆ ์ด๋‹ค. Virtual DOM๋Š” ๋ธŒ๋ผ์šฐ์ € API๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ Javascript ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ๊ตฌํ˜„๋œ ๊ฐœ๋…์ด๋‹ค.

  27. React Fiber๋ž€?

    Fiber๋Š” React v16์—์„œ ์ƒˆ๋กœ์šด ์กฐ์ •๋œ ์—”์ง„ ๋˜๋Š” ํ•ต์‹ฌ ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ์žฌ๊ตฌํ˜„์ด๋‹ค. React Fiber์˜ ๋ชฉํ‘œ๋Š” ์• ๋‹ˆ๋ฉ”์ด์…˜, ๋ ˆ์ด์•„์›ƒ, ์ œ์Šค์ฒ˜, ์ž‘์—… ์ผ์‹œ์ค‘์ง€, ์ค‘๋‹จ, ์žฌ์‚ฌ์šฉ ๊ฐ™์€ ์˜์—ญ์— ๋Œ€ํ•œ ์ ํ•ฉ์„ฑ์„ ๋†’์ด๊ณ  ๋‹ค์–‘ํ•œ ์œ ํ˜•์˜ ์—…๋ฐ์ดํŠธ์— ์šฐ์„ ์ˆœ์œ„๋ฅผ ์ •ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

  28. React Fiber์˜ ์ฃผ์š” ๋ชฉํ‘œ๋Š”??

    React Fiber์˜ ๋ชฉํ‘œ๋Š” ์• ๋‹ˆ๋ฉ”์ด์…˜, ๋ ˆ์ด์•„์›ƒ, ์ œ์Šค์ฒ˜, ์ž‘์—… ์ผ์‹œ์ค‘์ง€, ์ค‘๋‹จ, ์žฌ์‚ฌ์šฉ ๊ฐ™์€ ์˜์—ญ์— ๋Œ€ํ•œ ์ ํ•ฉ์„ฑ์„ ๋†’์ด๋Š” ๊ฒƒ์ด๋‹ค. ์ฃผ์š” ๊ธฐ๋Šฅ์€ incremental rendering์œผ๋กœ ๋ Œ๋”๋ง ์ž‘์—…์„ ์ฒญํฌ(chunk)๋กœ ๋ถ„ํ• ํ•˜๊ณ  ์—ฌ๋Ÿฌ ํ”„๋ ˆ์ž„์— ๊ฑธ์ณ ํŽผ์น˜๋Š” ๊ธฐ๋Šฅ์ด๋‹ค.

  29. controlled components๋ž€?

    ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ ๋’ค ํผ์˜ ์ž…๋ ฅ์ฐฝ์„ ์ œ์–ดํ•˜๋Š” component๋ฅผ Controlled Component๋ผ๊ณ  ํ•œ๋‹ค. ์ฆ‰ ๋ชจ๋“  ์ƒํƒœ ๋ณ€์ด์—๋Š” ๊ด€๋ จ๋œ ํ•ธ๋“ค๋Ÿฌ ํ•จ์ˆ˜๊ฐ€ ์žˆ๋‹ค.

    ์˜ˆ๋ฅผ ๋“ค์–ด, ๋ชจ๋“  ์ด๋ฆ„์„ ๋Œ€๋ฌธ์ž๋กœ ์ž‘์„ฑํ•˜๊ธฐ ์œ„ํ•ด์„œ, ์•„๋ž˜์™€ ๊ฐ™์€ handleChange๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

    handleChange(event) {
      this.setState({value: event.target.value.toUpperCase()})
    }
  30. uncontrolled components๋ž€?

    The Uncontrolled Components๋Š” ๋‚ด๋ถ€์ ์œผ๋กœ ์ž์‹ ์˜ ์ƒํƒœ๋ฅผ ์ €์žฅํ•˜๋Š” ๊ฒƒ์œผ๋กœ, ํ˜„์žฌ์˜ ๊ฐ’์„ ์ฐพ๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•˜๋‹ค๋ฉด ref๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ DOM์—์„œ ์ฐพ์•„์˜จ๋‹ค. ์ด๊ฒƒ์€ ์ „ํ†ต์ ์ธ HTML๊ณผ ๋” ๋น„์Šทํ•˜๋‹ค.

    ์•„๋ž˜์˜ UserProfile component์—์„œ, ์ด๋ฆ„ ์ž…๋ ฅ์€ ref๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์•ก์„ธ์Šคํ•œ๋‹ค.

    class UserProfile extends React.Component {
      constructor(props) {
        super(props)
        this.handleSubmit = this.handleSubmit.bind(this)
        this.input = React.createRef()
      }
    
      handleSubmit(event) {
        alert('A name was submitted: ' + this.input.current.value)
        event.preventDefault()
      }
    
      render() {
        return (
          <form onSubmit={this.handleSubmit}>
            <label>
              {'Name:'}
              <input type="text" ref={this.input} />
            </label>
            <input type="submit" value="Submit" />
          </form>
        );
      }
    }

    ๋Œ€๋ถ€๋ถ„์˜ ๊ฒฝ์šฐ ์–‘์‹์„ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐ controlled components๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ์ถ”์ฒœํ•œ๋‹ค.

  31. createElement์™€ cloneElement์˜ ์ฐจ์ด์ ์€?

    JSX elements๋Š” React.createElement() ํ•จ์ˆ˜๋กœ ์˜ฎ๊ฒจ์ ธ์„œ UI์˜ ๊ฐ์ฒด ํ‘œํ˜„์— ์‚ฌ์šฉ๋˜๋Š” React elements๋ฅผ ๋งŒ๋“ ๋‹ค. ๋ฐ˜๋ฉด์— cloneElement์€ element๋ฅผ ๋ณต์‚ฌํ•˜๊ณ  ์ƒˆ๋กœ์šด props๋กœ ์ „๋‹ฌํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋œ๋‹ค.

  32. React์—์„œ Lifting State Up๋ž€?

    ์—ฌ๋Ÿฌ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋™์ผํ•œ ๋ณ€๊ฒฝ ๋ฐ์ดํ„ฐ๋ฅผ ๊ณต์œ ํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ๊ณตํ†ต ์กฐ์ƒ์œผ๋กœ lift the shared state up์„ ํ•˜๋Š” ๊ฒƒ์„ ์ถ”์ฒœํ•œ๋‹ค. ์ฆ‰ 2๊ฐœ์˜ ์ž์‹ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ถ€๋ชจ๋กœ๋ถ€ํ„ฐ ๋™์ผํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ณต์œ ํ•˜๋Š” ๊ฒฝ์šฐ, ๋ชจ๋“  ์ž์‹ ์ปดํฌ๋„ŒํŠธ์—์„œ ๋กœ์ปฌ ์ƒํƒœ๋ฅผ ์œ ์ง€ํ•˜๋Š” ๋Œ€์‹ ์— ์ƒํƒœ๋ฅผ ๋ถ€๋ชจ์—์„œ ๊ด€๋ฆฌํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

  33. ์ปดํฌ๋„ŒํŠธ ๋ผ์ดํ”„ ์‚ฌ์ดํด์˜ ๋‹ค๋ฅธ ๋‹จ๊ณ„๋“ค์€?

    ์ปดํฌ๋„ŒํŠธ ๋ผ์ดํ”„ ์‚ฌ์ดํด๋Š” ์„ธ ๊ฐ€์ง€์˜ ๊ณ ์œ ํ•œ ๋‹จ๊ณ„๊ฐ€ ์žˆ๋‹ค.

    1. Mounting: ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ธŒ๋ผ์šฐ์ € DOM์— mount ํ•  ์ค€๋น„๊ฐ€ ๋˜์—ˆ๋‹ค. ์ด ๋‹จ๊ณ„๋Š” constructor(), getDerivedStateFromProps(), render(), componentDidMount() ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์„œ๋“œ์˜ ์ดˆ๊ธฐํ™”์— ๋Œ€ํ•ด ๋‹ค๋ฃฌ๋‹ค.

    2. Updating: ์ด ๋‹จ๊ณ„์—์„œ๋Š”, ์ปดํฌ๋„ŒํŠธ๋Š” ๋‘ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์œผ๋กœ ์—…๋ฐ์ดํŠธ๊ฐ€ ๋˜๋Š”๋ฐ, ์ƒˆ๋กœ์šด props๋ฅผ ๋ณด๋‚ด๊ฑฐ๋‚˜, setState() ๋˜๋Š” forceUpdate()์œผ๋กœ state๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ์ด ๋‹จ๊ณ„์—์„œ๋Š” getDerivedStateFromProps(), shouldComponentUpdate(), render(), getSnapshotBeforeUpdate(), componentDidUpdate() ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์„œ๋“œ๋ฅผ ๋‹ค๋ฃฌ๋‹ค.

    3. Unmounting: ์ด ๋งˆ์ง€๋ง‰ ๋‹จ๊ณ„์—์„œ๋Š”, ์ปดํฌ๋„ŒํŠธ๋Š” ํ•„์š”ํ•˜์ง€ ์•Š์œผ๋ฉฐ ๋ธŒ๋ผ์šฐ์ € DOM์—์„œ unmount๋œ๋‹ค. ์ด ๋‹จ๊ณ„์—์„œ๋Š” componentWillUnmount() ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์„œ๋“œ๊ฐ€ ํฌํ•จ๋œ๋‹ค.

    React๋Š” DOM์— ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ์ ์šฉํ•  ๋•Œ ๋‚ด๋ถ€์ ์œผ๋กœ ๋‹จ๊ณ„์˜ ๊ฐœ๋…์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ์–ธ๊ธ‰ํ•  ํ•„์š”๊ฐ€ ์žˆ๋‹ค. ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ถ„๋ฆฌ๋œ๋‹ค.

    1. Render ์ปดํฌ๋„ŒํŠธ๋Š” ๋ถ€์ˆ˜ ํšจ๊ณผ ์—†์ด ๋ Œ๋”๋ง ๋œ๋‹ค. Pure ์ปดํฌ๋„ŒํŠธ์— ์ ์šฉ๋˜๋ฉฐ ์ด ๋‹จ๊ณ„์—์„œ React๋Š” ๋ Œ๋”๋ง์„ ์ผ์‹œ ์ •์ง€, ์ค‘๋‹จ ๋˜๋Š” ์žฌ์‹œ์ž‘ํ•  ์ˆ˜ ์žˆ๋‹ค.

    2. Pre-commit ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์‹ค์ œ๋กœ DOM์— ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ์ ์šฉํ•˜๊ธฐ ์ „์—, React๊ฐ€ getSnapshotBeforeUpdate()๋ฅผ ํ†ตํ•ด์„œ DOM์„ ์ฝ์„ ์ˆ˜ ์žˆ๋Š” ์ˆœ๊ฐ„์ด๋‹ค.

    3. Commit React๋Š” DOM๊ณผ ํ•จ๊ป˜ ์ž‘๋™ํ•˜๊ณ  Mount๋ฅผ ์œ„ํ•œ componentDidMount(), ์—…๋ฐ์ดํŠธ๋ฅผ ์œ„ํ•œ componentDidMount(), Unmount๋ฅผ ์œ„ํ•œ componentWillUnmount()์˜ ์ตœ์ข… ๋ผ์ดํ”„ ์‚ฌ์ดํด์„ ๊ฐ๊ฐ ์‹คํ–‰ํ•œ๋‹ค.

    React 16.3+ ๋‹จ๊ณ„ (๋˜๋Š”) ์ผ๋ฐ˜์ ์ธ ๋ฒ„์ „)

    phases 16.3+

    React 16.3 ์ „์—๋Š”

    phases 16.2

  34. React์˜ ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์„œ๋“œ์—๋Š” ๋ฌด์—‡์ด ์žˆ๋‚˜?

    React 16.3+

    • getDerivedStateFromProps: render()๊ฐ€ ํ˜ธ์ถœ๋˜๊ธฐ ๋ฐ”๋กœ ์ „์— ํ˜ธ์ถœ๋˜๋ฉฐ ๋ชจ๋“  ๋ Œ๋”๋ง์—์„œ ํ˜ธ์ถœ๋œ๋‹ค. ์ด์ „ state๊ฐ€ ํ•„์š”ํ•œ ๋“œ๋ฌธ ๊ฒฝ์šฐ์— ์‚ฌ์šฉ์ด ๋œ๋‹ค. ์ด์ „ state๊ฐ€ ํ•„์š”ํ•˜๋ฉด ์ฝ์„๋งŒํ•œ ๊ฐ€์น˜๊ฐ€ ์žˆ๋‹ค.
    • componentDidMount: ์ฒซ ๋ฒˆ์งธ ๋ Œ๋”๋ง ์ดํ›„์— ์‹คํ–‰๋˜๊ณ , ์—ฌ๊ธฐ์„œ ๋ชจ๋“  AJAX ์š”์ฒญ, DOM ๋˜๋Š” state ์—…๋ฐ์ดํŠธ ๋ฐ ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ๊ฐ€ ์„ค์ •๋œ๋‹ค.
    • shouldComponentUpdate: ์ปดํฌ๋„ŒํŠธ๋ฅผ ์—…๋ฐ์ดํŠธ ํ•ด์•ผ ํ• ์ง€ ์—ฌ๋ถ€๋ฅผ ๊ฒฐ์ •ํ•œ๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ true๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. state๋‚˜ props๊ฐ€ ์—…๋ฐ์ดํŠธ๋œ ํ›„์— ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ Œ๋”๋งํ•  ํ•„์š” ์—†๋‹ค๊ณ  ํ™•์‹ ํ•˜๋Š” ๊ฒฝ์šฐ false๋ฅผ ๋ฐ˜ํ™˜ํ•  ์ˆ˜ ์žˆ๋‹ค. ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ƒˆ๋กœ์šด props๋ฅผ ๋ฐ›์œผ๋ฉด ๋ฆฌ๋ Œ๋”๋งํ•˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•  ์ˆ˜ ์žˆ์–ด ์„ฑ๋Šฅ์„ ํ–ฅ์ƒํ•˜๋Š”๋ฐ ๋งค์šฐ ์ข‹๋‹ค.
    • getSnapshotBeforeUpdate: ๋ Œ๋”๋ง ๋œ ์ถœ๋ ฅ์ด DOM์— ์ปค๋ฐ‹๋˜๊ธฐ ๋ฐ”๋กœ ์ง์ „์— ์‹คํ–‰๋œ๋‹ค. ์ด๋กœ ์ธํ•ด ๋ชจ๋“  ๊ฐ’์€ componentDidUpdate()์— ์ „๋‹ฌ์ด ๋œ๋‹ค. DOM์—์„œ ์Šคํฌ๋กค ์œ„์น˜ ๊ฐ™์€ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ๋ฐ ์œ ์šฉํ•˜๋‹ค.
    • componentDidUpdate: ์ฃผ๋กœ props๋‚˜ state์˜ ๋ณ€๊ฒฝ์— ๋Œ€ํ•œ ์‘๋‹ต์œผ๋กœ DOM์„ ์—…๋ฐ์ดํŠธํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋œ๋‹ค. shouldComponentUpdate()๊ฐ€ false๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋ฉด ์‹คํ–‰๋˜์ง€ ์•Š๋Š”๋‹ค.
    • componentWillUnmount ๋‚˜๊ฐ€๋Š” ๋„คํŠธ์›Œํฌ ์š”์ฒญ์„ ์ทจ์†Œํ•˜๊ฑฐ๋‚˜ ์ปดํฌ๋„ŒํŠธ์™€ ๊ด€๋ จ๋œ ๋ชจ๋“  ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ๋ฅผ ์ œ๊ฑฐํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋œ๋‹ค.

    Before 16.3

    • componentWillMount: ๋ Œ๋”๋ง ์ „์— ์‹คํ–‰๋˜๋ฉฐ root ์ปดํฌ๋„ŒํŠธ์˜ App ์ˆ˜์ค€ ๊ตฌ์„ฑ์„ ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋œ๋‹ค.
    • componentDidMount: ์ฒซ ๋ฒˆ์งธ ๋ Œ๋”๋ง ์ดํ›„์— ์‹คํ–‰๋˜๊ณ , ์—ฌ๊ธฐ์„œ ๋ชจ๋“  AJAX ์š”์ฒญ, DOM ๋˜๋Š” state ์—…๋ฐ์ดํŠธ ๋ฐ ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ๊ฐ€ ์„ค์ •๋œ๋‹ค.
    • componentWillReceiveProps: ํŠน์ • props ์—…๋ฐ์ดํŠธ๊ฐ€ state ์ „ํ™˜์„ ์ผ์œผํ‚ฌ ๋•Œ ์‹คํ–‰๋œ๋‹ค.
    • shouldComponentUpdate: ์ปดํฌ๋„ŒํŠธ๋ฅผ ์—…๋ฐ์ดํŠธ ํ•ด์•ผ ํ• ์ง€ ์—ฌ๋ถ€๋ฅผ ๊ฒฐ์ •ํ•œ๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ true๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. state๋‚˜ props๊ฐ€ ์—…๋ฐ์ดํŠธ๋œ ํ›„์— ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ Œ๋”๋งํ•  ํ•„์š” ์—†๋‹ค๊ณ  ํ™•์‹ ํ•˜๋Š” ๊ฒฝ์šฐ false๋ฅผ ๋ฐ˜ํ™˜ํ•  ์ˆ˜ ์žˆ๋‹ค. ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ƒˆ๋กœ์šด props๋ฅผ ๋ฐ›์œผ๋ฉด ๋ฆฌ๋ Œ๋”๋งํ•˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•  ์ˆ˜ ์žˆ์–ด ์„ฑ๋Šฅ์„ ํ–ฅ์ƒํ•˜๋Š”๋ฐ ๋งค์šฐ ์ข‹๋‹ค.
    • componentWillUpdate: true๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” shouldComponentUpdate()์— ์˜ํ•ด ํ™•์ธ๋œ props ๋ฐ state ๋ณ€๊ฒฝ์ด ์žˆ์„ ๋•Œ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ฆฌ๋ Œ๋”๋งํ•˜๊ธฐ ์ „์— ์‹คํ–‰๋œ๋‹ค.
    • componentDidUpdate: ์ฃผ๋กœ props๋‚˜ state ๋ณ€๊ฒฝ์— ๋Œ€ํ•œ ์‘๋‹ต์œผ๋กœ DOM์„ ์—…๋ฐ์ดํŠธํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋œ๋‹ค.
    • componentWillUnmount: ๋‚˜๊ฐ€๋Š” ๋„คํŠธ์›Œํฌ ์š”์ฒญ์„ ์ทจ์†Œํ•˜๊ฑฐ๋‚˜ ์ปดํฌ๋„ŒํŠธ์™€ ๊ด€๋ จ๋œ ๋ชจ๋“  ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ๋ฅผ ์ œ๊ฑฐํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋œ๋‹ค.
  35. ๊ณ ์ฐจ(Higher-Order) ์ปดํฌ๋„ŒํŠธ๋ž€?

    ๊ณ ์ฐจ(Higher-Order) ์ปดํฌ๋„ŒํŠธ (HOC)๋Š” ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ฐ€์ ธ์™€์„œ ์ƒˆ๋กœ์šด ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜์ด๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ, ์ปดํฌ๋„ŒํŠธ ๊ตฌ์„ฑ์ƒ์˜ ๋ณธ์งˆ์—์„œ ํŒŒ์ƒ๋œ ํŒจํ„ด์ด๋‹ค.

    ๋™์ ์œผ๋กœ ์ œ๊ณต๋œ ์ž์‹ ์ปดํฌ๋„ŒํŠธ๋Š” ํ—ˆ์šฉํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, ์ž…๋ ฅ ์ปดํฌ๋„ŒํŠธ์˜ ์–ด๋– ํ•œ ๋™์ž‘์„ ์ˆ˜์ •ํ•˜๊ฑฐ๋‚˜ ๋ณต์‚ฌํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ ์ˆœ์ˆ˜ ์ปดํฌ๋„ŒํŠธ(pure components) ๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค.

    const EnhancedComponent = higherOrderComponent(WrappedComponent)

    HOC๋Š” ์•„๋ž˜์™€ ๊ฐ™์€ ๋งŽ์€ ์‚ฌ๋ก€์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

    1. ์ฝ”๋“œ ์žฌ์‚ฌ์šฉ, ๋…ผ๋ฆฌ ๋ฐ ๋ถ€ํŠธ์ŠคํŠธ๋žฉ ์ถ”์ƒํ™”
    2. ๋„์šฉ ๋ Œ๋”๋ง
    3. State ์ถ”์ƒํ™” ๋ฐ ์กฐ์ž‘
    4. Props ์กฐ์ž‘.
  36. HOC ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•ด์„œ props ํ”„๋ก์‹œ๋ฅผ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์€?

    ๋‹ค์Œ๊ณผ ๊ฐ™์ด props proxy ํŒจํ„ด์„ ์‚ฌ์šฉํ•˜์—ฌ ์ปดํฌ๋„ŒํŠธ์— ์ „๋‹ฌ๋œ props๋ฅผ ์ถ”๊ฐ€/ํŽธ์ง‘ํ•  ์ˆ˜ ์žˆ๋‹ค.

    function HOC(WrappedComponent) {
      return class Test extends Component {
        render() {
          const newProps = {
            title: 'New Header',
            footer: false,
            showFeatureX: false,
            showFeatureY: true
          }
    
          return <WrappedComponent {...this.props} {...newProps} />
        }
      }
    }
  37. context๋ž€?

    Context๋Š” ์ˆ˜๋™์œผ๋กœ ๋ชจ๋“  ๋‹จ๊ณ„์— props๋ฅผ ์ „๋‹ฌํ•˜์ง€ ์•Š๊ณ  ์ปดํฌ๋„ŒํŠธ ํŠธ๋ฆฌ๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ๋ฅผ ์ „๋‹ฌํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ œ๊ณตํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์ธ์ฆ๋œ ์‚ฌ์šฉ์ž, locale ๊ธฐ๋ณธ ์„ค์ •, UI ํ…Œ๋งˆ๋Š” ๋งŽ์€ ์ปดํฌ๋„ŒํŠธ๋ฅผ ํ†ตํ•ด ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์—์„œ ์•ก์„ธ์Šคํ•ด์•ผ ํ•œ๋‹ค.

    const {Provider, Consumer} = React.createContext(defaultValue)
  38. children prop์ด๋ž€?

    Children(this.prop.children)๋Š” ๋‹ค๋ฅธ prop์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๋‹ค๋ฅธ ์ปดํฌ๋„ŒํŠธ์— ๋ฐ์ดํ„ฐ๋ฅผ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋Š” ์š”์†Œ(this.prop.children)๋‹ค. ์ปดํฌ๋„ŒํŠธ์˜ ์—ฌ๋Š” ํƒœ๊ทธ์™€ ๋‹ซ๋Š” ํƒœ๊ทธ ์‚ฌ์ด์— ๋†“์ธ ์ปดํฌ๋„ŒํŠธ ํŠธ๋ฆฌ๊ฐ€ ํ•ด๋‹น ์ปดํฌ๋„ŒํŠธ์˜ children prop๋กœ ์ „๋‹ฌ๋œ๋‹ค.

    ์ด prop์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด React API์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค. ์—ฌ๊ธฐ์—๋Š”React.Children.map,React.Children.forEach,React.Children.count,React.Children.only,React.Children.toArray๊ฐ€ ํฌํ•จ๋œ๋‹ค. children prop์˜ ๊ฐ„๋‹จํ•œ ์‚ฌ์šฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

    const MyDiv = React.createClass({
      render: function() {
        return <div>{this.props.children}</div>
      }
    })
    
    ReactDOM.render(
      <MyDiv>
        <span>{'Hello'}</span>
        <span>{'World'}</span>
      </MyDiv>,
      node
    )
  39. React์—์„œ ์ฃผ์„์„ ์–ด๋–ป๊ฒŒ ๋‹ค๋Š”๊ฐ€?

    React / JSX์˜ ์ฃผ์„์€ JavaScript Multiline ์ฃผ์„๊ณผ ์œ ์‚ฌํ•˜์ง€๋งŒ ์ค‘๊ด„ํ˜ธ๋กœ ๋ฌถ์ธ๋‹ค.

    Single-line comments:

    <div>
      {/* ํ•œ ์ค„ ์ฃผ์„ (๋ฐ”๋‹๋ผ ์ž๋ฐ” ์Šคํฌ๋ฆฝํŠธ์—์„œ๋Š” ํ•œ ์ค„ ์ฃผ์„์€ ์ด์ค‘ ์Šฌ๋ž˜์‹œ (//)๋กœ ํ‘œ์‹œ๋œ๋‹ค) */}
      {`Welcome ${user}, let's play React`}
    </div>

    Multi-line comments:

    <div>
      {/* ํ•œ ์ค„์ด์ƒ์˜
        ์—ฌ๋Ÿฌ ์ค„ ์ฃผ์„ */}
      {`Welcome ${user}, let's play React`}
    </div>
  40. props argument๊ฐ€ ์žˆ๋Š” ์ƒ์„ฑ์ž์—์„œ super๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ชฉ์ ์€ ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?

    ์ž์‹ ํด๋ž˜์Šค ์ƒ์„ฑ์ž๋Š”super()๋ฉ”์„œ๋“œ๊ฐ€ ํ˜ธ์ถœ ๋  ๋•Œ๊นŒ์ง€ this๋ฅผ ์ฐธ์กฐํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ES6 ํ•˜์œ„ ํด๋ž˜์Šค์—๋„ ๋™์ผํ•˜๊ฒŒ ์ ์šฉ๋œ๋‹ค. super() ํ˜ธ์ถœ์— props ๋งค๊ฐœ ๋ณ€์ˆ˜๋ฅผ ์ „๋‹ฌํ•˜๋Š” ์ฃผ์š”ํ•œ ์ด์œ ๋Š” ์ž์‹ ์ƒ์„ฑ์ž์—์„œ this.props์— ์ ‘๊ทผํ•˜๊ธฐ ์œ„ํ•ด์„œ๋‹ค.

    props ์ „๋‹ฌ

    class MyComponent extends React.Component {
      constructor(props) {
        super(props)
    
        console.log(this.props) // prints { name: 'John', age: 42 }
      }
    }

    props ๋ฏธ์ „๋‹ฌ

    class MyComponent extends React.Component {
      constructor(props) {
        super()
    
        console.log(this.props) // prints undefined
    
        // but props parameter is still available
        console.log(props) // prints { name: 'John', age: 42 }
      }
    
      render() {
        // no difference outside constructor
        console.log(this.props) // prints { name: 'John', age: 42 }
      }
    }

    ์œ„ ์ฝ”๋“œ๋ฅผ ๋ณด๋ฉด this.props๊ฐ€ ์ƒ์„ฑ์ž ๋‚ด์—์„œ๋งŒ ๋‹ค๋ฅธ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค. ์ƒ์„ฑ์ž ๋ฐ–์—์„œ๋Š” ๋™์ผํ•˜๋‹ค.

  41. ์กฐ์ •(reconciliation)์ด๋ž€?

    ์ปดํฌ๋„ŒํŠธ์˜ props๋‚˜ state๊ฐ€ ๋ณ€๊ฒฝ๋˜์—ˆ์„ ๋•Œ, React๋Š” ์ƒˆ๋กœ ๋ฐ˜ํ™˜๋œ ์—˜๋ฆฌ๋จผํŠธ์™€ ์ด์ „์— ๋ Œ๋”๋ง๋œ ๊ฒƒ์„ ๋น„๊ตํ•ด์„œ ์‹ค์ œ DOM์ด ์—…๋ฐ์ดํŠธ๊ฐ€ ํ•„์š”ํ•œ์ง€๋ฅผ ๊ฒฐ์ •ํ•œ๋‹ค. ๋™๋“ฑํ•˜์ง€ ์•Š์„ ๋•Œ, React๊ฐ€ DOM์„ ์—…๋ฐ์ดํŠธํ•  ๊ฒƒ์ด๋‹ค. ์ด ํ”„๋กœ์„ธ์Šค๋ฅผ *์กฐ์ •(reconciliation)*์ด๋ผ๊ณ  ํ•œ๋‹ค.

  42. state์˜ ํ‚ค ์ด๋ฆ„์„ ๋™์ ์œผ๋กœ ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    ES6๋‚˜ Babel transpiler๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ JSX์ฝ”๋“œ๋ฅผ ๋ณ€ํ™˜ํ•˜๋Š” ๊ฒฝ์šฐ ์›ํ•˜๋Š” ์†์„ฑ(property)๋ช…์œผ๋กœ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

    handleInputChange(event) {
      this.setState({ [event.target.id]: event.target.value })
    }
  43. ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ Œ๋”๋ง ๋  ๋•Œ๋งˆ๋‹ค ํ˜ธ์ถœ๋˜๋Š” ํ•จ์ˆ˜์— ๋Œ€ํ•œ ์‹ค์ˆ˜๋Š” ๋ฌด์—‡์ผ๊นŒ?

    ํ•จ์ˆ˜๋ฅผ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ „๋‹ฌํ•˜๋Š” ๋™์•ˆ ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœ๋˜์ง€ ์•Š๋„๋ก ํ™•์ธํ•ด์•ผ ํ•œ๋‹ค.

    render() {
      // Wrong: handleClick is called instead of passed as a reference!
      return <button onClick={this.handleClick()}>{'Click Me'}</button>
    }

    ๋Œ€์‹ ์—, ๊ด„ํ˜ธ ์—†์ด ํ•จ์ˆ˜ ์ž์ฒด๋ฅผ ์ „๋‹ฌํ•ด์•ผ ํ•œ๋‹ค.

    render() {
      // Correct: handleClick is passed as a reference!
      return <button onClick={this.handleClick}>{'Click Me'}</button>
    }
  44. ์™œ ์ปดํฌ๋„ŒํŠธ ์ด๋ฆ„์€ ๋Œ€๋ฌธ์ž๋กœ ํ•ด์•ผ ํ•˜๋‚˜?

    ์ปดํฌ๋„ŒํŠธ๋Š” DOM ์—˜๋ฆฌ๋จผํŠธ๊ฐ€ ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์— ๋Œ€๋ฌธ์ž๋กœ ํ‘œ๊ธฐํ•ด์•ผ ํ•œ๋‹ค. ๋˜ํ•œ, JSX ์†Œ๋ฌธ์ž ํƒœ๊ทธ ์ด๋ฆ„์€ HTML ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ๋‚˜ํƒ€๋‚ด๋ฉฐ ์ปดํฌ๋„ŒํŠธ๋Š” ์ฐธ์กฐํ•˜์ง€ ์•Š๋Š”๋‹ค.

  45. React๋Š” ์™œ class๊ฐ€ ์•„๋‹Œ className ์†์„ฑ์„ ์‚ฌ์šฉํ•˜๋‚˜?

    class๋Š” JavasScript์˜ ํ‚ค์›Œ๋“œ์ด๋ฉฐ, JSX๋Š” JavaScript์˜ ํ™•์žฅ์ด๋‹ค. ์ด๊ฒƒ์ด React๊ฐ€ class ๋Œ€์‹  className์„ ์‚ฌ์šฉํ•˜๋Š” ์ฃผ๋œ ์ด์œ ์ด๋‹ค. className prop์œผ๋กœ ๋ฌธ์ž์—ด์„ ๋„˜๊ฒจ์•ผ ํ•œ๋‹ค.

    render() {
      return <span className={'menu navigation-menu'}>{'Menu'}</span>
    }
  46. fragments๋ž€?

    ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์—ฌ๋Ÿฌ ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉํ•˜๋Š” React์˜ ์ผ๋ฐ˜์ ์ธ ํŒจํ„ด์ด๋‹ค. Fragments๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด DOM์— ๋…ธ๋“œ๋ฅผ ์ถ”๊ฐ€ํ•˜์ง€ ์•Š๊ณ  ์ž์‹ ๋ชฉ๋ก์„ ๊ทธ๋ฃนํ™”ํ•  ์ˆ˜ ์žˆ๋‹ค.

    render() {
      return (
        <React.Fragment>
          <ChildA />
          <ChildB />
          <ChildC />
        </React.Fragment>
      )
    }

    ๋”์šฑ๋” ์งง์€ ๊ตฌ๋ฌธ๋„ ์žˆ์ง€๋งŒ, ๋งŽ์€ ๋„๊ตฌ์—์„œ ์ง€์›ํ•˜์ง€ ์•Š๋Š”๋‹ค.

    render() {
      return (
        <>
          <ChildA />
          <ChildB />
          <ChildC />
        </>
      )
    }
  47. div๋ณด๋‹ค fragments๊ฐ€ ๋” ์šฐ์ˆ˜ํ•œ ์ด์œ ๋Š”?

    1. Fragments๋Š” ์กฐ๊ธˆ ๋” ๋น ๋ฅด๋ฉฐ ์—ฌ๋ถ„์˜ DOM ๋…ธ๋“œ๋ฅผ ๋งŒ๋“ค์ง€ ์•Š์•„์„œ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๋œ ์‚ฌ์šฉํ•œ๋‹ค. ์ด๊ฒƒ์€ ๋งค์šฐ ํฌ๊ณ  ๊นŠ์€ ํŠธ๋ฆฌ(tree)์—์„œ ์‹ค์งˆ์ ์ธ ์ด๋“์„ ๊ฐ€์ ธ๋‹ค์ค€๋‹ค.
    2. Flexbox์™€ CSS Grid ๊ฐ™์€ ์ผ๋ถ€ CSS ๋ฉ”์ปค๋‹ˆ์ฆ˜์—๋Š” ํŠน์ˆ˜ํ•œ ๋ถ€๋ชจ-์ž์‹ ๊ด€๊ณ„๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์–ด์„œ, ์ค‘๊ฐ„์— div๋ฅผ ์ถ”๊ฐ€ํ•˜๋ฉด ์›ํ•˜๋Š” ๋ ˆ์ด์•„์›ƒ์„ ์œ ์ง€ํ•˜๊ธฐ๊ฐ€ ์–ด๋ ต๋‹ค.
    3. DOM Inspector๊ฐ€ ๋œ ๋ณต์žกํ•ด์ง„๋‹ค.
  48. React์˜ portals์ด๋ž€?

    Portal์€ ์ƒ์œ„ ์ปดํฌ๋„ŒํŠธ์˜ DOM ๊ณ„์ธต ๊ตฌ์กฐ ์™ธ๋ถ€์— ์žˆ๋Š” DOM ๋…ธ๋“œ์— ์ž์‹์„ ๋ Œ๋”๋งํ•˜๋Š”๋ฐ ๊ถŒ์žฅ๋˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.

    ReactDOM.createPortal(child, container)

    ์ฒซ ๋ฒˆ์งธ ์ธ์ˆ˜๋Š” ๋ Œ๋”๋ง ๊ฐ€๋Šฅํ•œ React ์—˜๋ฆฌ๋จผํŠธ, ๋ฌธ์ž์—ด, fragment ๊ฐ™์€ ํ•˜์œ„์š”์†Œ์ด๋‹ค. ๋‘ ๋ฒˆ์งธ ์ธ์ˆ˜๋Š” DOM ์—˜๋ฆฌ๋จผํŠธ์ด๋‹ค.

  49. stateless ์ปดํฌ๋„ŒํŠธ๋ž€?

    ๋™์ž‘์ด state์™€ ๊ด€๋ จ์ด ์—†๋Š” ๊ฒฝ์šฐ stateless ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋  ์ˆ˜ ์žˆ๋‹ค. function์ด๋‚˜ class๋ฅผ ์‚ฌ์šฉํ•ด์„œ stateless ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค. ์ปดํฌ๋„ŒํŠธ์—์„œ ๋ผ์ดํ”„ ์‚ฌ์ดํด ํ›…์„ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์•„๋‹ˆ๋ผ๋ฉด function ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๊ฒŒ ์ข‹๋‹ค. function ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์—ฌ๋Ÿฌ ์ด์ ์ด ์žˆ๋Š”๋ฐ, ์“ฐ๊ธฐ, ์ดํ•ด ๋ฐ ํ…Œ์ŠคํŠธํ•˜๊ธฐ๊ฐ€ ์‰ฝ๊ณ  ๋” ๋น ๋ฅด๋ฉฐ, this ํ‚ค์›Œ๋“œ๋ฅผ ํ”ผํ•  ์ˆ˜ ์žˆ๋‹ค.

  50. stateful ์ปดํฌ๋„ŒํŠธ๋ž€?

    ์ปดํฌ๋„ŒํŠธ์˜ ๋™์ž‘์ด ์ปดํฌ๋„ŒํŠธ์˜ state์— ๋”ฐ๋ผ ๋‹ฌ๋ผ์ง„๋‹ค๋ฉด stateful ์ปดํฌ๋„ŒํŠธ๋ผ๊ณ  ํ•  ์ˆ˜ ์žˆ๋‹ค. stateful ์ปดํฌ๋„ŒํŠธ๋Š” ํ•ญ์ƒ class ์ปดํฌ๋„ŒํŠธ ์ด๋ฉฐ constructor์—์„œ ์ดˆ๊ธฐํ™”๊ฐ€ ๋˜์–ด state๋ฅผ ๊ฐ€์ง€๊ฒŒ ๋œ๋‹ค.

    class App extends Component {
      constructor(props) {
        super(props)
        this.state = { count: 0 }
      }
    
      render() {
        // ...
      }
    }
  51. React์—์„œ props ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฅผ ์ ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์ด development ๋ชจ๋“œ์—์„œ ์‹คํ–‰๋  ๋•Œ, React๋Š” ์ž๋™์œผ๋กœ ์ปดํฌ๋„ŒํŠธ์— ์„ค์ •ํ•œ ๋ชจ๋“  props๋ฅผ ํ™•์ธํ•˜์—ฌ ์˜ฌ๋ฐ”๋ฅธ ํƒ€์ž…์ธ์ง€ ํ™•์ธํ•œ๋‹ค. ํƒ€์ž…์ด ๋งž์ง€ ์•Š๋Š”๋‹ค๋ฉด, React๋Š” ์ฝ˜์†”์— ๊ฒฝ๊ณ  ๋ฉ”์‹œ์ง€๋ฅผ ๋„์šด๋‹ค. production ๋ชจ๋“œ์—์„œ๋Š” ์„ฑ๋Šฅ์— ์˜ํ–ฅ์„ ๋ฏธ์น˜๋ฏ€๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค. ์ฃผ์š”ํ•œ props๋Š” isRequired๋กœ ์ •์˜๋œ๋‹ค.

    ์‚ฌ์ „ ์ •์˜๋œ props ํƒ€์ž…์ด๋‹ค.

    1. PropTypes.number
    2. PropTypes.string
    3. PropTypes.array
    4. PropTypes.object
    5. PropTypes.func
    6. PropTypes.node
    7. PropTypes.element
    8. PropTypes.bool
    9. PropTypes.symbol
    10. PropTypes.any

    ๋‹ค์Œ๊ณผ ๊ฐ™์ด User ์ปดํฌ๋„ŒํŠธ์— ๋Œ€ํ•œ propTypes์„ ์ •์˜ํ•  ์ˆ˜ ์žˆ๋‹ค.

    import React from 'react'
    import PropTypes from 'prop-types'
    
    class User extends React.Component {
      static propTypes = {
        name: PropTypes.string.isRequired,
        age: PropTypes.number.isRequired
      }
    
      render() {
        return (
          <>
            <h1>{`Welcome, ${this.props.name}`}</h1>
            <h2>{`Age, ${this.props.age}`}</h2>
          </>
        )
      }
    }

    Note: React v15.5๋ฒ„์ „์—์„œ PropTypes๋Š” React.PropTypes์—์„œ prop-types ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ์ด๋™๋˜์—ˆ๋‹ค.

  52. React์˜ ์žฅ์ ์€?

    1. Virtual DOM์œผ๋กœ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์„ฑ๋Šฅ์ด ํ–ฅ์ƒ๋œ๋‹ค.
    2. JSX๋Š” ์ฝ”๋“œ๋ฅผ ์ฝ๊ณ  ์“ฐ๊ธฐ ์‰ฝ๊ฒŒ ํ•ด์ค€๋‹ค.
    3. ํด๋ผ์ด์–ธํŠธ์™€ ์„œ๋ฒ„์‚ฌ์ด๋“œ(SSR) ๋ Œ๋”๋ง์ด ๋‘˜ ๋‹ค ๊ฐ€๋Šฅํ•˜๋‹ค.
    4. ์˜ค์ง view ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๊ธฐ ๋•Œ๋ฌธ์—, ํ”„๋ ˆ์ž„์›Œํฌ(Angular, Backbone)์— ์‰ฝ๊ฒŒ ํ†ตํ•ฉ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
    5. Jest์™€ ๊ฐ™์€ ํˆด์„ ์‚ฌ์šฉํ•˜์—ฌ ๋‹จ์œ„ ๋ฐ ํ†ตํ•ฉ ํ…Œ์ŠคํŠธ๋ฅผ ์‰ฝ๊ฒŒ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.
  53. React์˜ ํ•œ๊ณ„๋Š”?

    1. React๋Š” ํ”„๋ ˆ์ž„์›Œํฌ๊ฐ€ ์•„๋‹Œ, view ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๋‹ค.
    2. ์›น ๊ฐœ๋ฐœ์„ ์ฒ˜์Œ ์ ‘ํ•˜๋Š” ์ดˆ๋ณด์ž์—๊ฒŒ ๋Ÿฌ๋‹ ์ปค๋ธŒ๊ฐ€ ์กด์žฌํ•œ๋‹ค.
    3. ๊ธฐ์กด MVC ํ”„๋ ˆ์ž„์›Œํฌ์— React๋ฅผ ํ†ตํ•ฉํ•˜๋ ค๋ฉด ๋ช‡ ๊ฐ€์ง€ ์ถ”๊ฐ€ ๊ตฌ์„ฑ์ด ํ•„์š”ํ•˜๋‹ค.
    4. ์ธ๋ผ์ธ ํ…œํ”Œ๋ฆฟ๊ณผ JSX๋กœ ์ธํ•ด ์ฝ”๋“œ ๋ณต์žก์„ฑ์ด ์ฆ๊ฐ€ํ•œ๋‹ค.
    5. ๋„ˆ๋ฌด ๋งŽ์€ ์ž‘์€ ์ปดํฌ๋„ŒํŠธ๋Š” ์—”์ง€๋‹ˆ์–ด๋ง ๋˜๋Š” ๋ณด์ผ๋Ÿฌ ํ”Œ๋ ˆ์ดํŠธ๋กœ ์ด์–ด์ง„๋‹ค.
  54. React v16์—์„œ error boundaries๋ž€ ๋ฌด์—‡์ธ๊ฐ€?

    Error boundaries๋Š” ํ•˜์œ„ ์ปดํฌ๋„ŒํŠธ์˜ ๋ชจ๋“  ์œ„์น˜์—์„œ JavaScript ์˜ค๋ฅ˜๋ฅผ catchํ•˜๊ณ , ์˜ค๋ฅ˜๋ฅผ ๊ธฐ๋กํ•˜๋ฉฐ, ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ ์ปดํฌ๋„ŒํŠธ ํŠธ๋ฆฌ ๋Œ€์‹  ํด๋ฐฑ(fallback) UI๋ฅผ ํ‘œ์‹œํ•˜๋Š” ์ปดํฌ๋„ŒํŠธ์ด๋‹ค.

    ํด๋ž˜์Šค ์ปดํฌ๋„ŒํŠธ๋Š” componentDidCatch(error, info) ๋˜๋Š” static getDerivedStateFromError()๋ผ๋Š” ์ƒˆ๋กœ์šด ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์„œ๋“œ๋ฅผ ์ •์˜ํ•˜๋ฉด error boundary๊ฐ€ ๋œ๋‹ค.

    class ErrorBoundary extends React.Component {
      constructor(props) {
        super(props)
        this.state = { hasError: false }
      }
    
      componentDidCatch(error, info) {
        // You can also log the error to an error reporting service
        logErrorToMyService(error, info)
      }
    
      static getDerivedStateFromError(error) {
         // Update state so the next render will show the fallback UI.
         return { hasError: true };
       }
    
      render() {
        if (this.state.hasError) {
          // You can render any custom fallback UI
          return <h1>{'Something went wrong.'}</h1>
        }
        return this.props.children
      }
    }

    ๊ทธ๋Ÿฐ ๋‹ค์Œ ์ผ๋ฐ˜ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

    <ErrorBoundary>
      <MyWidget />
    </ErrorBoundary>
  55. React v15์—์„œ๋Š” ์–ด๋–ป๊ฒŒ error boundaries ์กฐ์ž‘ํ•˜๋‚˜?

    React v15์—์„œ๋Š” unstable_handleError ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ error boundaries ์— ๋Œ€ํ•œ ๋งค์šฐ ๊ธฐ๋ณธ์ ์ธ ์ง€์›์„ ์ œ๊ณตํ•œ๋‹ค. React v16์—์„œ componentDidCatch๋กœ ์ด๋ฆ„์ด ๋ณ€๊ฒฝ๋˜์—ˆ๋‹ค.

  56. ์ •์  ํƒ€์ž… ๊ฒ€์‚ฌ์— ๊ถŒ์žฅ๋˜๋Š” ๋ฐฉ๋ฒ•์€?

    ์ผ๋ฐ˜์ ์œผ๋กœ ์šฐ๋ฆฌ๋Š” React ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ํƒ€์ž… ๊ฒ€์‚ฌ๋ฅผ ์œ„ํ•ด PropTypes ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. (React v15.5 ์ดํ›„ React.PropTypes๋Š” prop-types ํŒจํ‚ค์ง€๋กœ ์˜ฎ๊ฒจ์ง.) ํฐ ์ฝ”๋“œ ๊ธฐ๋ฐ˜์˜ ๊ฒฝ์šฐ, ์ปดํŒŒ์ผ ํƒ€์ž„์— ํƒ€์ž…๊ฒ€์‚ฌ๋ฅผ ํ•˜๊ณ  ์ž๋™ ์™„์„ฑ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๋Š” Flow๋‚˜ TypeScript ๊ฐ™์€ ์ •์  ํƒ€์ž… ๊ฒ€์‚ฌ๊ธฐ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.

  57. react-dom ํŒจํ‚ค์ง€ ์‚ฌ์šฉ๋ฒ•์€?

    react-dom ํŒจํ‚ค์ง€๋Š” ์•ฑ์˜ ์ตœ์ƒ์œ„ ๋ ˆ๋ฒจ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” DOM-๊ด€๋ จ ๋ฉ”์„œ๋“œ๋ฅผ ์ œ๊ณตํ•œ๋‹ค. ๋Œ€๋ถ€๋ถ„์˜ ์ปดํฌ๋„ŒํŠธ๋Š” ์ด ๋ชจ๋“ˆ์„ ์‚ฌ์šฉํ•  ํ•„์š”๊ฐ€ ์—†๋‹ค. ์ด ํŒจํ‚ค์ง€์˜ ์ผ๋ถ€ ๋ฉ”์„œ๋“œ๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

    1. render()
    2. hydrate()
    3. unmountComponentAtNode()
    4. findDOMNode()
    5. createPortal()
  58. react-dom์˜ render ๋ฉ”์„œ๋“œ๋ž€?

    ์ด ๋ฉ”์„œ๋“œ๋Š” React ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ์ œ๊ณต๋œ ์ปจํ…Œ์ด๋„ˆ์˜ DOM์— ๋ Œ๋”๋งํ•˜๊ณ  ์ปดํฌ๋„ŒํŠธ์— ๋Œ€ํ•œ ์ฐธ์กฐ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋œ๋‹ค. React ์—˜๋ฆฌ๋จผํŠธ๊ฐ€ ์ด์ „์— ์ปจํ…Œ์ด๋„ˆ๋กœ ๋ Œ๋”๋ง ๋œ ๊ฒฝ์šฐ, ํ•ด๋‹น ์—˜๋ฆฌ๋จผํŠธ์— ๋Œ€ํ•œ ์—…๋ฐ์ดํŠธ๋ฅผ ์ˆ˜ํ–‰ํ•˜๊ณ  ํ•„์š”์— ๋”ฐ๋ผ ์ตœ์‹  ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ๋ฐ˜์˜ํ•˜๊ธฐ ์œ„ํ•ด DOM์„ ๋ณ€๊ฒฝํ•œ๋‹ค.

    ReactDOM.render(element, container[, callback])
    

    ์„ ํƒ์  ์ฝœ๋ฐฑ์ด ์ œ๊ณต๋˜๋ฉด, ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ Œ๋”๋ง ๋˜๊ฑฐ๋‚˜ ์—…๋ฐ์ดํŠธ ๋์„ ๋•Œ ์‹คํ–‰๋œ๋‹ค.

  59. ReactDOMServer๋ž€?

    ReactDOMServer ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ •์  ๋งˆํฌ์—…(์ผ๋ฐ˜์ ์œผ๋กœ ๋…ธ๋“œ ์„œ๋ฒ„์—์„œ ์‚ฌ์šฉํ•œ๋‹ค.)์œผ๋กœ ๋ Œ๋”๋งํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด ๊ฐ์ฒด๋Š” ์ฃผ๋กœ ์„œ๋ฒ„ ์‚ฌ์ด๋“œ ๋ Œ๋”๋ง(SSR) ์— ์‚ฌ์šฉ๋œ๋‹ค. ์•„๋ž˜์˜ ๋ฉ”์„œ๋“œ๋“ค์€ ์„œ๋ฒ„์™€ ๋ธŒ๋ผ์šฐ์ € ํ™˜๊ฒฝ์—์„œ ๋ชจ๋‘ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

    1. renderToString()
    2. renderToStaticMarkup()

    ์˜ˆ๋ฅผ ๋“ค์–ด, ์ผ๋ฐ˜์ ์œผ๋กœ Express, Hapi, ๋˜๋Š” Koa์™€ ๊ฐ™์€ ๋…ธ๋“œ ๊ธฐ๋ฐ˜ ์›น ์„œ๋ฒ„๋ฅผ ์‹คํ–‰ํ•˜๊ณ  renderToString๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ๋ฃจํŠธ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ฌธ์ž์—ด๋กœ ๋ Œ๋”๋งํ•œ ๋‹ค์Œ ์‘๋‹ต์œผ๋กœ ๋ณด๋‚ธ๋‹ค.

    // using Express
    import { renderToString } from 'react-dom/server'
    import MyPage from './MyPage'
    
    app.get('/', (req, res) => {
      res.write('<!DOCTYPE html><html><head><title>My Page</title></head><body>')
      res.write('<div id="content">')
      res.write(renderToString(<MyPage/>))
      res.write('</div></body></html>')
      res.end()
    })
  60. React์—์„œ innerHTML๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•?

    dangerouslySetInnerHTML๋Š” ๋ธŒ๋ผ์šฐ์ € DOM์—์„œ innerHTML๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ React์˜ ๋Œ€์ฒด ์†์„ฑ์ด๋‹ค. innerHTML๊ณผ ๊ฐ™์ด, ํฌ๋กœ์Šค-์‚ฌ์ดํŠธ ์Šคํฌ๋ฆฝํŒ…(XSS) ๊ณต๊ฒฉ์„ ๊ณ ๋ คํ•˜์—ฌ ์ด ์†์„ฑ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ ์œ„ํ—˜ํ•˜๋‹ค. __html ๊ฐ์ฒด๋ฅผ ํ‚ค๋กœ ์ „๋‹ฌํ•˜๊ณ  HTML ํ…์ŠคํŠธ๋ฅผ ๊ฐ’์œผ๋กœ ์ „๋‹ฌํ•˜๋ฉด ๋œ๋‹ค.

    ์ด ์˜ˆ์ œ์—์„œ MyComponent๋Š” HTML ๋งˆํฌ์—… ์„ค์ •์„ ์œ„ํ•ด dangerouslySetInnerHTML ์†์„ฑ์„ ์‚ฌ์šฉํ•œ๋‹ค.

    function createMarkup() {
      return { __html: 'First &middot; Second' }
    }
    
    function MyComponent() {
      return <div dangerouslySetInnerHTML={createMarkup()} />
    }
  61. React์—์„œ ์Šคํƒ€์ผ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•?

    style ์†์„ฑ์€ CSS ๋ฌธ์ž์—ด ๋Œ€์‹ ์— camelCased ์†์„ฑ์ด ์žˆ๋Š” JavaScript ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ์ด๊ฒƒ์€ DOM ์Šคํƒ€์ผ JavaScript ์†์„ฑ๊ณผ ์ผ์น˜ํ•˜๋ฉฐ, ๋ณด๋‹ค ํšจ์œจ์ ์ด๊ณ , XSS ๋ณด์•ˆ ์ทจ์•ฝ์ ์„ ๋ฐฉ์ง€ํ•œ๋‹ค.

    const divStyle = {
      color: 'blue',
      backgroundImage: 'url(' + imgUrl + ')'
    };
    
    function HelloWorldComponent() {
      return <div style={divStyle}>Hello World!</div>
    }

    ์Šคํƒ€์ผ ํ‚ค๋Š” JavaScript์—์„œ DOM ๋…ธ๋“œ์˜ ์†์„ฑ(e.g. node.style.backgroundImage)์— ์•ก์„ธ์Šคํ•˜๋Š” ๊ฒƒ๊ณผ ์ผ๊ด€์„ฑ์„ ์œ ์ง€ํ•˜๊ธฐ ์œ„ํ•ด์„œ camelCased๋กœ ์ž‘์„ฑํ•œ๋‹ค.

  62. React์—์„œ ์ด๋ฒคํŠธ๊ฐ€ ์–ด๋–ป๊ฒŒ ๋‹ค๋ฅธ๊ฐ€?

    React ์—˜๋ฆฌ๋จผํŠธ์˜ ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฌธ๋ฒ•์  ์ฐจ์ด๊ฐ€ ์žˆ๋‹ค.

    1. React ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ๋Š” ์†Œ๋ฌธ์ž๊ฐ€ ์•„๋‹Œ camelCase๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ช…๋ช…๋œ๋‹ค.
    2. JSX์—์„œ๋Š” ๋ฌธ์ž์—ด์ด ์•„๋‹Œ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ๋กœ ํ•จ์ˆ˜๋ฅผ ์ „๋‹ฌํ•œ๋‹ค.
  63. ์ƒ์„ฑ์ž์—์„œ setState()๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์–ด๋–ป๊ฒŒ ๋˜๋‚˜?

    setState()๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด, React์— ๊ฐ์ฒด state๋ฅผ ํ• ๋‹นํ•˜๋Š” ๊ฒƒ๊ณผ ๋ณ„๊ฐœ๋กœ ์ปดํฌ๋„ŒํŠธ์™€ ๋ชจ๋“  ์ž์‹์„ ๋ฆฌ๋ Œ๋”๋งํ•œ๋‹ค. ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค. Can only update a mounted or mounting component. ๊ทธ๋ž˜์„œ this.state๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ƒ์„ฑ์ž ๋‚ด๋ถ€์˜ ๋ณ€์ˆ˜๋ฅผ ์ดˆ๊ธฐํ™”ํ•ด์•ผ ํ•œ๋‹ค.

  64. ํ‚ค๋กœ ์ธ๋ฑ์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด?

    React๊ฐ€ ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ์ถ”์ ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ‚ค๋Š” ์•ˆ์ •์ ์ด๊ณ  ์˜ˆ์ธก ๊ฐ€๋Šฅํ•˜๋ฉฐ ๊ณ ์œ ํ•ด์•ผ ํ•œ๋‹ค.

    ์•„๋ž˜์˜ ์ฝ”๋“œ ์กฐ๊ฐ์—์„œ ๊ฐ ์—˜๋ฆฌ๋จผํŠธ์˜ ํ‚ค๋Š” ํ‘œํ˜„๋˜๋Š” ๋ฐ์ดํ„ฐ์— ๋ฌถ์ด์ง€ ์•Š๊ณ  ์ˆœ์„œ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•œ๋‹ค. ์ด๊ฒƒ์€ React๊ฐ€ ํ•  ์ˆ˜ ์žˆ๋Š” ์ตœ์ ํ™”๋ฅผ ์ œํ•œํ•œ๋‹ค.

    {todos.map((todo, index) =>
      <Todo
        {...todo}
        key={index}
      />
    )}

    ์œ ๋‹ˆํฌํ•œ ํ‚ค์— ์—˜๋ฆฌ๋จผํŠธ ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ, todo.id๊ฐ€ ์ด ๋ชฉ๋ก์—์„œ ์œ ์ผํ•˜๊ณ  ์•ˆ์ •์ ์ด๋ผ๊ณ  ๊ฐ€์ •ํ•˜๋ฉด, React๋Š” ์š”์†Œ๋ฅผ ์žฌํ‰๊ฐ€ ํ•  ํ•„์š”์—†์ด ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ์žฌ์ •๋ ฌ ํ•  ์ˆ˜ ์žˆ๋‹ค.

    {todos.map((todo) =>
      <Todo {...todo}
        key={todo.id} />
    )}
  65. componentWillMount() ๋ฉ”์„œ๋“œ์—์„œ setState()๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ ์ข‹์€๊ฐ€?

    componentWillMount() ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์„œ๋“œ์—์„œ ๋น„๋™๊ธฐ ์ดˆ๊ธฐํ™”๋ฅผ ํ•˜์ง€ ์•Š๋Š”๊ฒŒ ์ข‹๋‹ค. componentWillMount()๋Š” ๋งˆ์šดํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜๊ธฐ ์ง์ „์— ํ˜ธ์ถœ๋œ๋‹ค. render() ์ „์— ํ˜ธ์ถœ๋˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฉ”์„œ๋“œ์—์„œ state๋ฅผ ์„ค์ •ํ•˜๋ฉด ๋ฆฌ๋ Œ๋”๋ง ๋˜์ง€ ์•Š๋Š”๋‹ค. ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฉ”์„œ๋“œ๋กœ ์‚ฌ์ด๋“œ ์ดํŽ™ํŠธ๋‚˜ ๊ตฌ๋…์„ ํ”ผํ•˜๋ฉด๋œ๋‹ค. componentWillMount() ๋Œ€์‹ ์— componentDidMount()์—์„œ ์ปดํฌ๋„ŒํŠธ ์ดˆ๊ธฐํ™”์— ๋Œ€ํ•œ ๋น„๋™๊ธฐ ํ˜ธ์ถœ์„ ํ•œ๋‹ค.

    componentDidMount() {
      axios.get(`api/todos`)
        .then((result) => {
          this.setState({
            messages: [...result.data]
          })
        })
    }
  66. ์ดˆ๊ธฐ state์— props๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์–ด๋–ป๊ฒŒ ๋˜๋‚˜?

    ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ƒˆ๋กœ ๊ณ ์นจ ์—†์ด ์ปดํฌ๋„ŒํŠธ์˜ props๋ฅผ ๋ณ€๊ฒฝํ•˜๋ฉด, ์ƒ์„ฑ์ž ํ•จ์ˆ˜๊ฐ€ ์ ˆ๋Œ€๋กœ ์ปดํฌ๋„ŒํŠธ์˜ ํ˜„์žฌ state๋ฅผ ์—…๋ฐ์ดํŠธํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ ์ƒˆ๋กœ์šด props ๊ฐ’์ด ํ‘œ์‹œ๋˜์ง€ ์•Š๋Š”๋‹ค. props๋กœ state ์ดˆ๊ธฐํ™”ํ•˜๋Š” ๊ฒƒ์€ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ฒ˜์Œ ๋งŒ๋“ค์–ด์งˆ ๋•Œ๋งŒ ์‹คํ–‰๋œ๋‹ค.

    ์•„๋ž˜์˜ ์ปดํฌ๋„ŒํŠธ๋Š” ์—…๋ฐ์ดํŠธ๋œ ์ž…๋ ฅ๊ฐ’์„ ํ‘œ์‹œํ•˜์ง€ ์•Š๋Š”๋‹ค.

    class MyComponent extends React.Component {
      constructor(props) {
        super(props)
    
        this.state = {
          records: [],
          inputValue: this.props.inputValue
        };
      }
    
      render() {
        return <div>{this.state.inputValue}</div>
      }
    }

    render ๋ฉ”์„œ๋“œ ์•ˆ์—์„œ props๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๊ฐ’์ด ์—…๋ฐ์ดํŠธ๋œ๋‹ค.

    class MyComponent extends React.Component {
      constructor(props) {
        super(props)
    
        this.state = {
          record: []
        }
      }
    
      render() {
        return <div>{this.props.inputValue}</div>
      }
    }
  67. ์ปดํฌ๋„ŒํŠธ๋ฅผ ์กฐ๊ฑด๋ถ€๋กœ ๋ Œ๋”๋งํ•˜๋Š” ๋ฐฉ๋ฒ•?

    ๊ฒฝ์šฐ์— ๋”ฐ๋ผ ์ผ๋ถ€ state์— ๋”ฐ๋ผ ๋‹ค๋ฅธ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ Œ๋”๋งํ•˜๋ ค๊ณ  ํ•œ๋‹ค. JSX๋Š” false ๋˜๋Š” undefined๋ฅผ ๋ Œ๋”๋งํ•˜์ง€ ์•Š์•„ ์กฐ๊ฑด๋ถ€ ๋‹จ๋ฝ์„ ์‚ฌ์šฉํ•˜์—ฌ ํŠน์ • ์กฐ๊ฑด์ด true์ธ ๊ฒฝ์šฐ์—๋งŒ ์ปดํฌ๋„ŒํŠธ์˜ ์ฃผ์–ด์ง„ ๋ถ€๋ถ„์„ ๋ Œ๋”๋งํ•  ์ˆ˜ ์žˆ๋‹ค.

    const MyComponent = ({ name, address }) => (
      <div>
        <h2>{name}</h2>
        {address &&
          <p>{address}</p>
        }
      </div>
    )

    if-else ์กฐ๊ฑด์ด ํ•„์š”ํ•˜๋ฉด ์‚ผํ•ญ ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

    const MyComponent = ({ name, address }) => (
      <div>
        <h2>{name}</h2>
        {address
          ? <p>{address}</p>
          : <p>{'Address is not available'}</p>
        }
      </div>
    )
  68. DOM ์—˜๋ฆฌ๋จผํŠธ์—์„œ spread props๋ฅผ ์กฐ์‹ฌํ•ด์•ผํ•˜๋Š” ์ด์œ ๋Š”?

    spread props ๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ์•Œ ์ˆ˜ ์—†๋Š” HTML ์†์„ฑ์„ ์ถ”๊ฐ€ํ•  ์œ„ํ—˜์ด ์žˆ๋‹ค. ์ด๋Š” ๋‚˜์œ ์Šต๊ด€์ด๋‹ค. ๋Œ€์‹  ์šฐ๋ฆฌ๋Š” ...rest ์—ฐ์‚ฐ์ž๋กœ props destructuring์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ, ํ•„์š”ํ•œ props๋งŒ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด,

    const ComponentA = () =>
      <ComponentB isDisplay={true} className={'componentStyle'} />
    
    const ComponentB = ({ isDisplay, ...domProps }) =>
      <div {...domProps}>{'ComponentB'}</div>
  69. React์—์„œ ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•?

    ์ปดํฌ๋„ŒํŠธ๋ฅผ ํ•จ์ˆ˜๋กœ ์ „๋‹ฌํ•˜๋Š” ๊ฒƒ๊ณผ ๋™์ผํ•˜๊ฒŒ, class ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊พธ๋ฐ€ ์ˆ˜ ์žˆ๋‹ค. ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ๋Š” ์ปดํฌ๋„ŒํŠธ ๊ธฐ๋Šฅ์„ ์ˆ˜์ •ํ•˜๋Š” ์œ ์—ฐํ•˜๊ณ  ์ฝ๊ธฐ ์‰ฌ์šด ๋ฐฉ๋ฒ•์ด๋‹ค.

    @setTitle('Profile')
    class Profile extends React.Component {
        //....
    }
    
    /*
      title์€ ๋ฌธ์„œ ์ œ๋ชฉ์œผ๋กœ ์„ค์ •๋  ๋ฌธ์ž์—ด์ด๋‹ค.
      WrappedComponent๋Š” ์šฐ๋ฆฌ์˜ ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ๊ฐ€ ์œ„์˜ ์˜ˆ์ œ์—์„œ ๋ณผ ์ˆ˜ ์žˆ๋“ฏ์ด ์ปดํฌ๋„ŒํŠธ ํด๋ž˜์Šค ๋ฐ”๋กœ ์œ„์— ๋†“๋Š”๋‹ค.
    */
    const setTitle = (title) => (WrappedComponent) => {
      return class extends React.Component {
        componentDidMount() {
          document.title = title
        }
    
        render() {
          return <WrappedComponent {...this.props} />
        }
      }
    }

    Note: ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ๋Š” ES7์— ํฌํ•จ๋˜์ง€ ์•Š์•˜์ง€๋งŒ, ํ˜„์žฌ stage 2 proposal์ด๋‹ค.

  70. ์ปดํฌ๋„ŒํŠธ๋ฅผ ์–ด๋–ป๊ฒŒ ๋ฉ”๋ชจํ•˜๋‚˜?

    ํ•จ์ˆ˜ํ˜• ์ปดํฌ๋„ŒํŠธ์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฉ”๋ชจ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด moize ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ๋‹ค๋ฅธ ์ปดํฌ๋„ŒํŠธ์— ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ฉ”๋ชจํ•  ์ˆ˜ ์žˆ๋‹ค.

    import moize from 'moize'
    import Component from './components/Component' // this module exports a non-memoized component
    
    const MemoizedFoo = moize.react(Component)
    
    const Consumer = () => {
      <div>
        {'I will memoize the following entry:'}
        <MemoizedFoo/>
      </div>
    }
  71. Server Side Rendering ๋˜๋Š” SSR ๊ตฌํ˜„๋ฐฉ๋ฒ•?

    React๋Š” ์ด๋ฏธ ๋…ธ๋“œ ์„œ๋ฒ„์—์„œ ๋ Œ๋”๋ง์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋„๋ก ์ค€๋น„๋˜์–ด ์žˆ๋‹ค. DOM ๋ Œ๋”๋Ÿฌ์˜ ํŠน์ˆ˜ ๋ฒ„์ „์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ ํด๋ผ์ด์–ธํŠธ ์ธก๊ณผ ๋™์ผํ•œ ํŒจํ„ด์„ ๋”ฐ๋ฅธ๋‹ค.

    import ReactDOMServer from 'react-dom/server'
    import App from './App'
    
    ReactDOMServer.renderToString(<App />)

    ์ด ๋ฉ”์„œ๋“œ๋Š” ์ผ๋ฐ˜ HTML์„ ๋ฌธ์ž์—ด๋กœ ์ถœ๋ ฅํ•˜๋ฉฐ, ์„œ๋ฒ„ ์‘๋‹ต์˜ ์ผ๋ถ€๋กœ ํŽ˜์ด์ง€ ๋ณธ๋ฌธ ๋‚ด์— ๋ฐฐ์น˜ํ•  ์ˆ˜ ์žˆ๋‹ค. ํด๋ผ์ด์–ธํŠธ ์ธก์—์„œ React๋Š” ์‚ฌ์ „ ๋ Œ๋”๋ง๋œ ์ปจํ…์ธ ๋ฅผ ํƒ์ง€ํ•˜๊ณ  ์ค‘๋‹จ๋œ ๋ถ€๋ถ„์„ ์™„๋ฒฝํ•˜๊ฒŒ ํŒŒ์•…ํ•œ๋‹ค.

  72. React์—์„œ production ๋ชจ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•?

    Webpack์˜ DefinePlugin ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด์„œ NODE_ENV๋ฅผ production ํ™˜๊ฒฝ์œผ๋กœ ์„ค์ •ํ•ด์•ผ propType ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ๋ฐ ์ถ”๊ฐ€ ๊ฒฝ๊ณ ์™€ ๊ฐ™์€ ์‚ฌํ•ญ์„ ์ œ๊ฑฐํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด์™€๋Š” ๋ณ„๊ฐœ๋กœ, Uglify์˜ ๊ฐœ๋ฐœ ์ฝ”๋“œ์™€ ์ฃผ์„์„ ์ œ๊ฑฐํ•˜๋Š” ๋ฐ๋“œ ์ฝ”๋“œ(dead-code) ์ œ๊ฑฐ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฒˆ๋“ค ํฌ๊ธฐ๋ฅผ ํฌ๊ฒŒ ์ค„์ผ ์ˆ˜ ์žˆ๋‹ค.

  73. CRA๋ž€ ๋ฌด์—‡์ด๋ฉฐ ์žฅ์ ์€?

    create-react-app CLI ํˆด์€ ๋ณ„๋„์˜ ๊ตฌ์„ฑ๋‹จ๊ณ„ ์—†์ด ๋น ๋ฅด๊ฒŒ React ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋งŒ๋“ค๊ณ  ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค.

    CRA๋กœ Todo ์•ฑ์„ ๋งŒ๋“ค์–ด๋ณด์ž

    # Installation
    $ npm install -g create-react-app
    
    # Create new project
    $ create-react-app todo-app
    $ cd todo-app
    
    # Build, test and run
    $ npm run build
    $ npm run test
    $ npm start

    React ์•ฑ์„ ์ œ์ž‘ํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ ๋ชจ๋“  ๊ฒƒ์ด ํฌํ•จ๋˜์–ด ์žˆ๋‹ค.

    1. React, JSX, ES6, ๋ฐ Flow ๋ฌธ๋ฒ• ์ง€์›.
    2. object spread operator์™€ ๊ฐ™์€ ES6๋ฅผ ๋„˜์–ด์„  ์–ธ์–ด ํ™•์žฅ ๊ธฐ๋Šฅ.
    3. ์ž๋™ ์ ‘๋‘์–ด๊ฐ€ ๋ถ™์€ CSS๋กœ, -webkit- ์ด๋‚˜ ๋‹ค๋ฅธ ์ ‘๋‘์‚ฌ๋Š” ํ•„์š” ์—†๋‹ค.
    4. coverage๋ฅผ ์ง€์›ํ•˜๋Š” ๋‚ด์žฅ๋œ ๋น ๋ฅธ ๋Œ€ํ™”ํ˜• ๋‹จ์œ„ ํ…Œ์ŠคํŠธ ๋Ÿฌ๋„ˆ.
    5. ์ผ๋ฐ˜์ ์ธ ์‹ค์ˆ˜์— ๋Œ€ํ•ด์„œ ๊ฒฝ๊ณ ํ•˜๋Š” ๋ผ์ด๋ธŒ ๊ฐœ๋ฐœ ์„œ๋ฒ„.
    6. hashes์™€ sourcemaps์„ ์‚ฌ์šฉํ•˜์—ฌ production ์šฉ JS, CSS ๋ฐ images๋ฅผ ๋ฌถ๋Š” ๋นŒ๋“œ ์Šคํฌ๋ฆฝํŠธ
  74. ๋งˆ์šดํŒ…์˜ ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์„œ๋“œ ์ˆœ์„œ๋Š”?

    ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์„œ๋“œ๋Š” ์ปดํฌ๋„ŒํŠธ ์ธ์Šคํ„ด์Šค๊ฐ€ ์ƒ์„ฑ๋˜์–ด DOM์— ์‚ฝ์ž…๋  ๋•Œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ˆœ์„œ๋กœ ํ˜ธ์ถœ๋œ๋‹ค.

    1. constructor()
    2. static getDerivedStateFromProps()
    3. render()
    4. componentDidMount()
  75. React v16์—์„œ ๋” ์ด์ƒ ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š” ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์„œ๋“œ๋Š”?

    ๋‹ค์Œ ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์†Œ๋“œ๋Š” ์•ˆ์ „ํ•˜์ง€ ์•Š์€ ์ฝ”๋”ฉ ๋ฐฉ๋ฒ•์ด๋ฉฐ ๋น„๋™๊ธฐ ๋ Œ๋”๋ง์—์„œ๋Š” ๋”์šฑ ๋ฌธ์ œ ๋  ๊ฒƒ์ด๋‹ค.

    1. componentWillMount()
    2. componentWillReceiveProps()
    3. componentWillUpdate()

    React v16.3์—์„œ ์œ„์˜ ๋ฉ”์„œ๋“œ๋“ค์€ UNSAFE_ ์ ‘๋‘์–ด๊ฐ€ ๋ณ„์นญ์œผ๋กœ ๋ถ™์–ด์ฃผ๊ธฐ ์‹œ์ž‘ํ–ˆ์œผ๋ฉฐ, React v17์—์„œ ์ ‘๋‘์–ด๊ฐ€ ์—†๋Š” ๋ฒ„์ „์€ ์ œ๊ฑฐ๋œ๋‹ค.

  76. getDerivedStateFromProps() ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์„œ๋“œ์˜ ์‚ฌ์šฉ ๋ชฉ์ ์€?

    ์ƒˆ๋กœ์šด ์ •์  getDerivedStateFromProps() ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์„œ๋“œ๋Š” ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ธ์Šคํ„ด์Šคํ™”๋œ ํ›„๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๋ฆฌ๋ Œ๋”๋ง ๋˜๊ธฐ ์ „์— ํ˜ธ์ถœ๋œ๋‹ค. update state๋ฅผ object๋กœ ๋Œ๋ ค์ค„ ์ˆ˜๋„ ์žˆ๊ณ , ์ƒˆ๋กœ์šด props๊ฐ€ state ์—…๋ฐ์ดํŠธ๋ฅผ ํ•˜์ง€ ์•Š์•„๋„ ๋˜๋Š” ๊ฒƒ์„ ๋‚˜ํƒ€๋‚ด๊ธฐ ์œ„ํ•ด null์„ ๋ฆฌํ„ดํ•  ์ˆ˜ ์žˆ๋‹ค.

    class MyComponent extends React.Component {
      static getDerivedStateFromProps(props, state) {
        // ...
      }
    }

    ์ด ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์„œ๋“œ๋Š” componentDidUpdate()์™€ componentWillReceiveProps()์˜ ๋ชจ๋“  ์‚ฌ์šฉ ์‚ฌ๋ก€๋ฅผ ์ปค๋ฒ„ํ•œ๋‹ค.

  77. getSnapshotBeforeUpdate() ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์„œ๋“œ์˜ ์‚ฌ์šฉ ๋ชฉ์ ์€??

    ์ƒˆ๋กœ์šด getSnapshotBeforeUpdate() ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์„œ๋“œ๋Š” DOM ์—…๋ฐ์ดํŠธ ์ง์ „์— ํ˜ธ์ถœ๋œ๋‹ค. ์ด ๋ฉ”์„œ๋“œ์˜ ๋ฐ˜ํ™˜ ๊ฐ’์€ ์„ธ ๋ฒˆ์งธ ๋งค๊ฐœ ๋ณ€์ˆ˜๋กœ componentDidUpdate()์— ์ „๋‹ฌ๋œ๋‹ค.

    class MyComponent extends React.Component {
      getSnapshotBeforeUpdate(prevProps, prevState) {
        // ...
      }
    }

    ์ด ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์„œ๋“œ๋Š” componentDidUpdate()์™€ componentWillUpdate()์˜ ๋ชจ๋“  ์‚ฌ์šฉ ์‚ฌ๋ก€๋ฅผ ์ปค๋ฒ„ํ•œ๋‹ค.

  78. Hooks๋Š” ๋ Œ๋”๋ง props์™€ ๊ณ ์ฐจ์› ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋Œ€์ฒดํ•œ๋‹ค?

    ๋ Œ๋”๋ง props์™€ ๊ณ ์ฐจ์› ์ปดํฌ๋„ŒํŠธ ๋ชจ๋‘ ํ•˜๋‚˜์˜ ์ž์‹๋งŒ ๋ Œ๋”๋งํ•˜์ง€๋งŒ, ๋Œ€๋ถ€๋ถ„์˜ ๊ฒฝ์šฐ Hooks๋Š” ํŠธ๋ฆฌ์—์„œ ์ค‘์ฒฉ์„ ์ค„์ž„์œผ๋กœ์จ ์ œ๊ฑฐํ•˜๋Š” ๋” ๊ฐ„๋‹จํ•œ ๋ฐฉ๋ฒ•์ด๋‹ค.

  79. ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ช…๋ช…ํ•˜๋Š”๋ฐ ๊ถŒ์žฅ๋˜๋Š” ๋ฐฉ๋ฒ•์€?

    displayName์„ ์‚ฌ์šฉํ•˜๋Š” ๋Œ€์‹  ์ฐธ์กฐ๋กœ ์ปดํฌ๋„ŒํŠธ์˜ ์ด๋ฆ„์„ ์ง€์ •ํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.

    ์ปดํฌ๋„ŒํŠธ ๋ช…๋ช…์— displayName๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ.

    export default React.createClass({
      displayName: 'TodoApp',
      // ...
    })

    ๊ถŒ์žฅ๋˜๋Š” ์ ‘๊ทผ ๋ฐฉ๋ฒ•:

    export default class TodoApp extends React.Component {
      // ...
    }
  80. ์ปดํฌ๋„ŒํŠธ ํด๋ž˜์Šค์—์„œ ๊ถŒ์žฅ๋˜๋Š” ๋ฉ”์„œ๋“œ ์ˆœ์„œ๋Š”?

    ๋งˆ์šดํŒ…์—์„œ ๋ Œ๋”๋ง ๋‹จ๊ณ„๊นŒ์ง€ ๊ถŒ์žฅ๋˜๋Š” ๋ฉ”์„œ๋“œ ์ˆœ์„œ๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

    1. static ๋ฉ”์„œ๋“œ
    2. constructor()
    3. getChildContext()
    4. componentWillMount()
    5. componentDidMount()
    6. componentWillReceiveProps()
    7. shouldComponentUpdate()
    8. componentWillUpdate()
    9. componentDidUpdate()
    10. componentWillUnmount()
    11. onClickSubmit() ๋˜๋Š” onChangeDescription()๊ณผ ๊ฐ™์€ ํ•ธ๋“ค๋Ÿฌ ๋˜๋Š” ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ๋ฅผ ํด๋ฆญ.
    12. getSelectReason() ๋˜๋Š” getFooterContent()์™€ ๊ฐ™์€ ๋ Œ๋”๋ง์„ ์œ„ํ•œ getter ๋ฉ”์„œ๋“œ
    13. renderNavigation() ๋˜๋Š” renderProfilePicture()์™€ ๊ฐ™์€ ์„ ํƒ์  ๋ Œ๋”๋ง ๋ฉ”์„œ๋“œ
    14. render()
  81. ์Šค์œ„์นญ ์ปดํฌ๋„ŒํŠธ๋ž€?

    ์Šค์œ„์นญ ์ปดํฌ๋„ŒํŠธ๋ž€๋Š” ๋งŽ์€ ์ปดํฌ๋„ŒํŠธ ์ค‘ ํ•˜๋‚˜๋ฅผ ๋ Œ๋”๋งํ•˜๋Š” ์ปดํฌ๋„ŒํŠธ์ด๋‹ค. prop ๊ฐ’์„ ์ปดํฌ๋„ŒํŠธ์— ๋งคํ•‘ํ•˜๋ ค๋ฉด object๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค.

    ์˜ˆ๋ฅผ ๋“ค์–ด, page prop์„ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•œ ๋‹ค๋ฅธ ํŽ˜์ด์ง€๋ฅผ ํ‘œ์‹œํ•˜๋Š” ์Šค์œ„์นญ ์ปดํฌ๋„ŒํŠธ.

    import HomePage from './HomePage'
    import AboutPage from './AboutPage'
    import ServicesPage from './ServicesPage'
    import ContactPage from './ContactPage'
    
    const PAGES = {
      home: HomePage,
      about: AboutPage,
      services: ServicesPage,
      contact: ContactPage
    }
    
    const Page = (props) => {
      const Handler = PAGES[props.page] || ContactPage
    
      return <Handler {...props} />
    }
    
    // PAGES ๊ฐ์ฒด์˜ ํ‚ค๋Š” prop ํƒ€์ž…์—์„œ ์‚ฌ์šฉ๋˜์–ด dev-time errors๋ฅผ ์žก์•„๋‚ผ ์ˆ˜ ์žˆ๋‹ค.
    Page.propTypes = {
      page: PropTypes.oneOf(Object.keys(PAGES)).isRequired
    }
  82. ์™œ setState()์— ํ•จ์ˆ˜๋ฅผ ์ „๋‹ฌํ•ด์•ผ ํ•˜๋‚˜?

    setState()๊ฐ€ ๋น„๋™๊ธฐ ์—ฐ์‚ฐ์ด๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ์„ฑ๋Šฅ์ƒ ์ด์œ ๋กœ React๋Š” state๋ฅผ ์ผ๊ด„์ ์œผ๋กœ ๋ณ€๊ฒฝํ•œ๋‹ค. ๊ทธ๋ž˜์„œ setState()๊ฐ€ ํ˜ธ์ถœ๋˜๊ณ  state๊ฐ€ ์ฆ‰์‹œ ๋ณ€๊ฒฝ๋˜์ง€ ์•Š๋Š”๋‹ค. ์ฆ‰ setState()โ€Š๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ํ˜„์žฌ ์ƒํƒœ์— ์˜์กดํ•ด์„œ๋Š” ์•ˆ ๋˜๋ฉฐ ๊ทธ ์ƒํƒœ๊ฐ€ ๋ฌด์—‡์ธ์ง€ ํ™•์‹ ํ•  ์ˆ˜ ์—†๊ฒŒ ๋œ๋‹ค. ํ•ด๊ฒฐ๋ฐฉ๋ฒ•์€ ์ด์ „ ์ƒํƒœ๋ฅผ ์ธ์ˆ˜๋กœ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด setState()์— ํ•จ์ˆ˜๋ฅผ ์ „๋‹ฌํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด setState()์˜ ๋น„๋™๊ธฐ ํŠน์„ฑ์œผ๋กœ ์ธํ•ด ์‚ฌ์šฉ์ž๊ฐ€ ์•ก์„ธ์Šคํ•  ๋•Œ ์ด์ „ ์ƒํƒœ ๊ฐ’์„ ๊ฐ€์ ธ์˜ค๋Š” ๋ฌธ์ œ๋ฅผ ํ”ผํ•  ์ˆ˜ ์žˆ๋‹ค.

    ์ดˆ๊ธฐ count ๊ฐ’์€ 0์ด๋ผ๊ณ  ๊ฐ€์ •ํ•ด๋ณด์ž. ์„ธ ๋ฒˆ์˜ ์—ฐ์† ์ฆ๊ฐ€ ์—ฐ์‚ฐ์„ ํ•˜๋ฉด, ๊ฐ’์€ 1๋งŒ ์ฆ๊ฐ€ํ•œ๋‹ค.

    // assuming this.state.count === 0
    this.setState({ count: this.state.count + 1 })
    this.setState({ count: this.state.count + 1 })
    this.setState({ count: this.state.count + 1 })
    // this.state.count === 1, not 3

    setState()์— ํ•จ์ˆ˜๋ฅผ ์ „๋‹ฌํ•˜๋ฉด, count๋Š” ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์ฆ๊ฐ€ํ•œ๋‹ค.

    this.setState((prevState, props) => ({
      count: prevState.count + props.increment
    }))
    // this.state.count === 3 as expected
  83. React์˜ strict mode๋ž€?

    React.StrictMode๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ž ์žฌ์ ์ธ ๋ฌธ์ œ์ ์„ ๊ฐ•์กฐ ํ‘œ์‹œํ•˜๋Š”๋ฐ ์œ ์šฉํ•œ ์ปดํฌ๋„ŒํŠธ์ด๋‹ค. <Fragment>์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ, <StrictMode>๋Š” ํŠน์ • DOM ์—˜๋ฆฌ๋จผํŠธ์— ๋ Œ๋”๋งํ•˜์ง€ ์•Š๋Š”๋‹ค. ์ž์†์— ๋Œ€ํ•œ ์ถ”๊ฐ€ ์ ๊ฒ€๊ณผ ๊ฒฝ๊ณ ๋ฅผ ํ™œ์„ฑํ™”ํ•œ๋‹ค. ์ด๋Ÿฌํ•œ ์ ๊ฒ€์€ ๊ฐœ๋ฐœ ๋ชจ๋“œ์—๋งŒ ์ ์šฉ์ด ๋œ๋‹ค.

    import React from 'react'
    
    function ExampleApplication() {
      return (
        <div>
          <Header />
          <React.StrictMode>
            <div>
              <ComponentOne />
              <ComponentTwo />
            </div>
          </React.StrictMode>
          <Footer />
        </div>
      )
    }

    ์œ„์˜ ์˜ˆ์ œ์—์„œ, strict mode ๊ฒ€์‚ฌ๋Š” <ComponentOne>์™€ <ComponentTwo> ์ปดํฌ๋„ŒํŠธ์—๋งŒ ์ ์šฉ๋œ๋‹ค.

  84. React Mixins์ด๋ž€?

    Mixins์€ ๊ณตํ†ต ๊ธฐ๋Šฅ์„ ๊ฐ–๋„๋ก ์ปดํฌ๋„ŒํŠธ๋ฅผ ์™„์ „ํžˆ ๋ถ„๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. Mixins์€ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•„์•ผ ํ•˜๋ฉฐ ๊ณ ์ฐจ์› ์ปดํฌ๋„ŒํŠธ๋‚˜ ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ๋กœ ๋Œ€์ฒดํ•  ์ˆ˜ ์žˆ๋‹ค.

    ๊ฐ€์žฅ ์ผ๋ฐ˜์ ์œผ๋กœ ์‚ฌ์šฉ๋˜๋Š” mixins์€ PureRenderMixin์ด๋‹ค. props์™€ state๊ฐ€ ์ด์ „ props, state์™€ ์–•๊ฒŒ ๋™๋“ฑํ•  ๋•Œ ๋ถˆํ•„์š”ํ•œ ๋ฆฌ๋ Œ๋”๋ง์„ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด ์ผ๋ถ€ ์ปดํฌ๋„ŒํŠธ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

    const PureRenderMixin = require('react-addons-pure-render-mixin')
    
    const Button = React.createClass({
      mixins: [PureRenderMixin],
      // ...
    })
  85. ์™œ isMounted()๊ฐ€ ์•ˆํ‹ฐ ํŒจํ„ด์ด๋ฉฐ ์ ์ ˆํ•œ ํ•ด๊ฒฐ์ฑ…์€?

    isMounted()์˜ ์ฃผ์š” ์‚ฌ์šฉ ์‚ฌ๋ก€๋Š” ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋งˆ์šดํŠธ ํ•ด์ œ๋œ ํ›„์— setState()๋ฅผ ํ˜ธ์ถœํ•˜์ง€ ์•Š๋„๋ก ๊ฒฝ๊ณ ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

    if (this.isMounted()) {
      this.setState({...})
    }

    setState()๋ฅผ ํ˜ธ์ถœํ•˜๊ธฐ ์ „์— isMounted()๋ฅผ ๊ฒ€์‚ฌํ•˜๋ฉด ๊ฒฝ๊ณ ๊ฐ€ ์ œ๊ฑฐ๋˜์ง€๋งŒ, ๊ฒฝ๊ณ ์˜ ๋ชฉ์ ๋„ ์ƒ์‹ค๋œ๋‹ค. ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋งˆ์šดํŠธ ํ•ด์ œ๋œ ํ›„์— ์ฐธ์กฐ๋ฅผ ๋ณด์œ ํ•˜๊ณ  ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•˜๊ธฐ ๋•Œ๋ฌธ์— isMounted()๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ ์ฝ”๋“œ ์Šค๋ฉœ์ด๋‹ค.

    ์ตœ์ ์˜ ํ•ด๊ฒฐ์ฑ…์€ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋งˆ์šดํŠธ ํ•ด์ œ๋œ ํ›„์— setState()๊ฐ€ ํ˜ธ์ถœ๋  ์ˆ˜ ์žˆ๋Š” ์œ„์น˜๋ฅผ ์ฐพ์•„ ์ˆ˜์ •ํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ์ด๋Ÿฌํ•œ ์ƒํ™ฉ์€ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ผ๋ถ€ ๋ฐ์ดํ„ฐ๋ฅผ ๊ธฐ๋‹ค๋ฆฌ๋ฉฐ, ๋ฐ์ดํ„ฐ๊ฐ€ ๋„์ฐฉํ•˜๊ธฐ ์ „์— ๋งˆ์šดํŠธ ํ•ด์ œ๋  ๋•Œ ์ฝœ๋ฐฑ์œผ๋กœ ์ธํ•ด ๊ฐ€์žฅ ์ผ๋ฐ˜์ ์œผ๋กœ ๋ฐœ์ƒํ•œ๋‹ค. ์ด์ƒ์ ์œผ๋กœ, ์ฝœ๋ฐฑ์€ ๋งˆ์šดํŠธ ํ•ด์ œ ์ „์— componentWillUnmount()์—์„œ ์ทจ์†Œํ•ด์•ผ ํ•œ๋‹ค.

  86. React์—์„œ ์ง€์›๋˜๋Š” Pointer Events๋Š”?

    Pointer Events๋Š” ๋ชจ๋“  ์ž…๋ ฅ ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ํ†ต์ผ๋œ ๋ฐฉ๋ฒ•์„ ์ œ๊ณตํ•œ๋‹ค. ์˜ˆ์ „์—๋Š” ๋งˆ์šฐ์Šค์™€ ๊ฐ๊ฐ์˜ ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ๊ฐ€ ์žˆ์—ˆ์ง€๋งŒ, ์š”์ฆ˜์—๋Š” ํ„ฐ์น˜์Šคํฌ๋ฆฐ์ด๋‚˜ ํŽœ์ด ๋‹ฌ๋ฆฐ ํœด๋Œ€์ „ํ™”์™€ ๊ฐ™์ด ๋งˆ์šฐ์Šค์™€ ๊ด€๋ จ ์—†๋Š” ์žฅ์น˜๊ฐ€ ๋งŽ๋‹ค. ์ด๋Ÿฌํ•œ ์ด๋ฒคํŠธ๋Š” Pointer Events ์‚ฌ์–‘์„ ์ง€์›ํ•˜๋Š” ๋ธŒ๋ผ์šฐ์ €์—์„œ๋งŒ ์ž‘๋™ํ•œ๋‹ค๋Š” ๊ฒƒ์„ ๊ธฐ์–ตํ•ด์•ผ ํ•œ๋‹ค.

    React DOM์—์„œ ๋‹ค์Œ ์ด๋ฒคํŠธ ์œ ํ˜•์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

    1. onPointerDown
    2. onPointerMove
    3. onPointerUp
    4. onPointerCancel
    5. onGotPointerCapture
    6. onLostPointerCaptur
    7. onPointerEnter
    8. onPointerLeave
    9. onPointerOver
    10. onPointerOut
  87. ์™œ ์ปดํฌ๋„ŒํŠธ์˜ ์ด๋ฆ„์€ ๋Œ€๋ฌธ์ž๋กœ ์‹œ์ž‘ํ•˜๋‚˜?

    JSX๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ Œ๋”๋งํ•˜๋Š” ๊ฒฝ์šฐ, ํ•ด๋‹น ์ปดํฌ๋„ŒํŠธ์˜ ์ด๋ฆ„์€ ๋Œ€๋ฌธ์ž๋กœ ์‹œ์ž‘ํ•ด์•ผ ํ•œ๋‹ค. ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด React๊ฐ€ ์ธ์‹ํ•  ์ˆ˜ ์—†๋Š” ํƒœ๊ทธ๋กœ ์˜ค๋ฅ˜๋ฅผ ๋ฐœ์ƒ์‹œํ‚จ๋‹ค. ์ด ๊ทœ์น™์€ HTML ์š”์†Œ์™€ SVG ํƒœ๊ทธ๋งŒ ์†Œ๋ฌธ์ž๋กœ ์‹œ์ž‘ํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์‚ฌ์šฉ๋œ๋‹ค.

    ์ด๋ฆ„์ด ์†Œ๋ฌธ์ž๋กœ ์‹œ์ž‘ํ•˜๋Š” ์ปดํฌ๋„ŒํŠธ ํด๋ž˜์Šค๋ฅผ ์ •์˜ํ•  ์ˆ˜ ์žˆ์ง€๋งŒ ๊ฐ€์ ธ์˜ฌ ๋•Œ ๋Œ€๋ฌธ์ž์—ฌ์•ผ ํ•œ๋‹ค. ์•„๋ž˜์™€ ๊ฐ™์€ ์†Œ๋ฌธ์ž๋Š” ๊ดœ์ฐฎ๋‹ค.

    class myComponent extends Component {
      render() {
        return <div />
      }
    }
    
    export default myComponent

    ๋‹ค๋ฅธ ํŒŒ์ผ์„ ๊ฐ€์ ธ์˜ฌ ๋•Œ ๋Œ€๋ฌธ์ž๋กœ ์‹œ์ž‘ํ•ด์•ผ ํ•œ๋‹ค.

    import MyComponent from './MyComponent'
  88. React v16์—์„œ ์‚ฌ์šฉ์ž ์ •์˜ DOM ์†์„ฑ์„ ์ง€์›ํ•˜๋‚˜?

    ๊ทธ๋ ‡๋‹ค. ๊ณผ๊ฑฐ์— React๋Š” ์•Œ ์ˆ˜ ์—†๋Š” DOM ์†์„ฑ์„ ๋ฌด์‹œํ•˜๊ณค ํ–ˆ๋‹ค. React๊ฐ€ ์ธ์‹ํ•˜์ง€ ๋ชปํ•˜๋Š” ์†์„ฑ์„ ๊ฐ€์ง„ JSX๋ฅผ ์ž‘์„ฑํ–ˆ๋‹ค๋ฉด React๋Š” ๊ทธ๋ƒฅ ๊ฑด๋„ˆ๋›ธ ๊ฒƒ์ด๋‹ค. ์˜ˆ๋ฅผ ๋“ค๋ฉด, ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

    <div mycustomattribute={'something'} />

    React v15๋กœ ๋นˆ div๋ฅผ DOM์— ๋ Œ๋”๋งํ•œ๋‹ค.

    <div />

    React v16์—์„œ๋Š” ์•Œ ์ˆ˜ ์—†๋Š” ์†์„ฑ์ด DOM์— ์ €์žฅ๋œ๋‹ค.

    <div mycustomattribute='something' />

    ์ด๊ฒƒ์€ ํŠน์ • ๋ธŒ๋ผ์šฐ์ € ๋น„ํ‘œ์ค€ ์†์„ฑ์„ ์ œ๊ณตํ•˜๊ณ , ์ƒˆ๋กœ์šด DOM API๋ฅผ ์‚ฌ์šฉํ•˜๊ณ , ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€ ํ†ตํ•ฉํ•  ๋•Œ ์œ ์šฉํ•˜๋‹ค.

  89. constructor๊ณผ getInitialState์˜ ์ฐจ์ด์ ์€?

    ES6์˜ ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ๋Š” ์ƒ์„ฑ์ž์—์„œ ์ƒํƒœ๋ฅผ ์ดˆ๊ธฐํ™”ํ•˜๊ณ  React.createClass()๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ๋Š” getInitialState() ๋ฉ”์„œ๋“œ๋ฅผ ์ดˆ๊ธฐํ™”ํ•ด์•ผ ํ•œ๋‹ค.

    ES6 ํด๋ž˜์Šค ์‚ฌ์šฉ ์‹œ

    class MyComponent extends React.Component {
      constructor(props) {
        super(props)
        this.state = { /* initial state */ }
      }
    }

    React.createClass() ์‚ฌ์šฉ ์‹œ

    const MyComponent = React.createClass({
      getInitialState() {
        return { /* initial state */ }
      }
    })

    Note: React.createClass()๋Š” ๋” ์ด์ƒ ์‚ฌ์šฉ๋˜์ง€ ์•Š์œผ๋ฉฐ React v16์—์„œ ์ œ๊ฑฐ๋˜์—ˆ๋‹ค. ๋Œ€์‹ ์— ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค.

  90. setState๋ฅผ ํ˜ธ์ถœํ•˜์ง€ ์•Š๊ณ ๋„ ์ปดํฌ๋„ŒํŠธ ๋ฆฌ๋ Œ๋”๋ง์ด ๊ฐ€๋Šฅํ•œ๊ฐ€?

    ๊ธฐ๋ณธ์ ์œผ๋กœ, ์ปดํฌ๋„ŒํŠธ์˜ state ๋˜๋Š” props๊ฐ€ ๋ณ€๊ฒฝ๋˜๋ฉด ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ฆฌ๋ Œ๋”๋ง์ด ๋œ๋‹ค. render() ๋ฉ”์„œ๋“œ๊ฐ€ ๋‹ค๋ฅธ ๋ฐ์ดํ„ฐ์— ์˜์กดํ•˜๋Š” ๊ฒฝ์šฐ, forceUpdate()๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ์ปดํฌ๋„ŒํŠธ์˜ ๋ Œ๋”๋ง์„ ๋‹ค์‹œ ํ•ด์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ์„ React์—๊ฒŒ ์•Œ๋ฆด ์ˆ˜ ์žˆ๋‹ค.

    component.forceUpdate(callback)

    forceUpdate()์˜ ์‚ฌ์šฉ์€ ํ”ผํ•˜๊ณ  render()์˜ this.props๊ณผ this.state์—์„œ ์ฝ๊ธฐ๋งŒ ํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.

  91. ES6 ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” React์—์„œ super()์™€ super(props)์˜ ์ฐจ์ด์ ์€?

    constructor()์—์„œ this.props์— ์ ‘๊ทผํ•˜๋ ค๋ฉด props๋ฅผ super() ๋ฉ”์„œ๋“œ์— ์ „๋‹ฌํ•ด์•ผ ํ•œ๋‹ค.

    super(props) ์‚ฌ์šฉ ์‹œ:

    class MyComponent extends React.Component {
      constructor(props) {
        super(props)
        console.log(this.props) // { name: 'John', ... }
      }
    }

    super() ์‚ฌ์šฉ ์‹œ:

    class MyComponent extends React.Component {
      constructor(props) {
        super()
        console.log(this.props) // undefined
      }
    }

    constructor() ์™ธ๋ถ€์—์„œ๋Š” this.props์— ๋Œ€ํ•ด์„œ ๊ฐ™์€ ๊ฐ’์„ ํ‘œ์‹œํ•œ๋‹ค.

  92. JSX ๋‚ด๋ถ€์—์„œ ๋ฐ˜๋ณตํ•˜๋Š” ๋ฐฉ๋ฒ•?

    ES6 ํ™”์‚ดํ‘œ ํ•จ์ˆ˜ ๊ตฌ๋ฌธ๊ณผ ํ•จ๊ป˜ Array.prototype.map์„ ๊ฐ„๋‹จํžˆ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๊ฐ์ฒด์˜ items ๋ฐฐ์—ด์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ปดํฌ๋„ŒํŠธ์˜ ๋ฐฐ์—ด๊ณผ ๋งคํ•‘๋œ๋‹ค.

    <tbody>
      {items.map(item => <SomeComponent key={item.id} name={item.name} />)}
    </tbody>

    for ๋ฐ˜๋ณต๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ˜๋ณตํ•  ์ˆ˜ ์—†๋‹ค.

    <tbody>
      for (let i = 0; i < items.length; i++) {
        <SomeComponent key={items[i].id} name={items[i].name} />
      }
    </tbody>

    JSX ํƒœ๊ทธ๊ฐ€ ํ•จ์ˆ˜ ํ˜ธ์ถœ๋กœ ๋ณ€ํ™˜๋˜์–ด ํ‘œํ˜„์‹์•ˆ์— ๋ช…๋ น๋ฌธ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ์ด๊ฒƒ์€ stage 1 proposal์— ์˜ฌ๋ผ๊ฐ€ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ฐ”๋€”์ˆ˜ ์žˆ๋‹ค.

  93. ์†์„ฑ ์ธ์šฉ๋ฌธ์— props๋ฅผ ์–ด๋–ป๊ฒŒ ๋„ฃ๋‚˜?

    React (๋˜๋Š” JSX)๋Š” ์†์„ฑ๊ฐ’ ๋‚ด๋ถ€์˜ ๋ณ€์ˆ˜ ๋ณด๊ฐ„์„ ์ง€์›ํ•˜์ง€ ์•Š๋Š”๋‹ค. ์•„๋ž˜์˜ ํ‘œํ˜„์€ ์ž‘๋™ํ•˜์ง€ ์•Š๋Š”๋‹ค.

    <img className='image' src='images/{this.props.image}' />

    ๊ทธ๋Ÿฌ๋‚˜ JS ํ‘œํ˜„์‹์„ ์ค‘๊ด„ํ˜ธ ์•ˆ์— ์ „์ฒด ์†์„ฑ๊ฐ’์œผ๋กœ ๋„ฃ์„ ์ˆ˜ ์žˆ๋‹ค. ๋”ฐ๋ผ์„œ, ์•„๋ž˜ ํ‘œํ˜„์‹์ด ์ž‘๋™ํ•œ๋‹ค.

    <img className='image' src={'images/' + this.props.image} />

    ํ…œํ”Œ๋ฆฟ ๋ฌธ์ž์—ด์„ ์‚ฌ์šฉํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

    <img className='image' src={`images/${this.props.image}`} />
  94. ๋ชจ์–‘์ด ์žˆ๋Š” React proptype array๋ž€?

    ํŠน์ • ๋ชจ์–‘์˜ ์ปดํฌ๋„ŒํŠธ์— ๊ฐ์ฒด ๋ฐฐ์—ด์„ ์ „๋‹ฌํ•˜๋ ค๋ฉด React.PropTypes.arrayOf()์— ๋Œ€ํ•œ ์ธ์ˆ˜๋กœ React.PropTypes.shape()๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

    ReactComponent.propTypes = {
      arrayWithShape: React.PropTypes.arrayOf(React.PropTypes.shape({
        color: React.PropTypes.string.isRequired,
        fontSize: React.PropTypes.number.isRequired
      })).isRequired
    }
  95. ํด๋ž˜์Šค ์†์„ฑ์„ ์กฐ๊ฑด๋ถ€๋กœ ์ ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    ๋”ฐ์˜ดํ‘œ ์•ˆ์—์„œ ์ค‘๊ด„ํ˜ธ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ฌธ์ž์—ด๋กœ ํ‰๊ฐ€๋˜๊ธฐ ๋•Œ๋ฌธ์— ์ค‘๊ด„ํ˜ธ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์•ˆ ๋œ๋‹ค.

    <div className="btn-panel {this.props.visible ? 'show' : 'hidden'}">

    ๋Œ€์‹  ์ค‘๊ด„ํ˜ธ๋ฅผ ๋ฐ”๊นฅ์œผ๋กœ ์˜ฎ๊ฒจ์•ผ ํ•œ๋‹ค. (ํด๋ž˜์Šค ์ด๋ฆ„๋“ค ์‚ฌ์ด์— ๊ณต๋ฐฑ์„ ๋„ฃ๋Š” ๊ฒƒ์„ ์žŠ์ง€ ๋ง์•„์•ผ ํ•œ๋‹ค.)

    <div className={'btn-panel ' + (this.props.visible ? 'show' : 'hidden')}>

    ํ…œํ”Œ๋ฆฟ ๋ฌธ์ž์—ด๋„ ์ž‘๋™ํ•œ๋‹ค.

    <div className={`btn-panel ${this.props.visible ? 'show' : 'hidden'}`}>
  96. React์™€ ReactDOM์˜ ์ฐจ์ด์ ?

    react ํŒจํ‚ค์ง€๋Š” React.createElement(), React.Component, React.Children, ์—˜๋ฆฌ๋จผํŠธ ์ปดํฌ๋„ŒํŠธ ๋ฐ ํด๋ž˜์Šค์™€ ๊ด€๋ จ๋œ ๊ธฐํƒ€ ๋„์šฐ๋ฏธ๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ๋‹ค. ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋งŒ๋“ค ๋•Œ ํ•„์š”ํ•œ ๋™ํ˜• ๋˜๋Š” ๋ณดํŽธ์ ์ธ ๋„์šฐ๋ฏธ๋ผ๊ณ  ์ƒ๊ฐํ•  ์ˆ˜ ์žˆ๋‹ค. react-dom ํŒจํ‚ค์ง€์—๋Š” ReactDOM.render()๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ๊ณ , react-dom/server์—๋Š” ReactDOMServer.renderToString()๊ณผ ReactDOMServer.renderToStaticMarkup()์„ ์‚ฌ์šฉํ•˜์—ฌ ์„œ๋ฒ„ ์‚ฌ์ด๋“œ ๋ Œ๋”๋ง์„ ์ง€์›ํ•œ๋‹ค.

  97. ์™œ ReactDOM์€ React์™€ ๋ถ„๋ฆฌ๋˜์—ˆ๋‚˜?

    React ํŒ€์€ ๋ชจ๋“  DOM ๊ด€๋ จ ๊ธฐ๋Šฅ์„ ReactDOM์ด๋ผ๋Š” ๋ณ„๋„์˜ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ๋ถ„๋ฆฌํ–ˆ๋‹ค. React v0.14๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ๋ถ„๋ฆฌ๋œ ์ฒซ ๋ฒˆ์งธ ๋ฆด๋ฆฌ์ฆˆ์ด๋‹ค. react-native, react-art, react-canvas, react-three ๊ฐ™์€ ์ผ๋ถ€ ํŒจํ‚ค์ง€๋ฅผ ์‚ดํŽด๋ณด๋ฉด, React์˜ ์•„๋ฆ„๋‹ค์›€๊ณผ ๋ณธ์งˆ์€ ๋ธŒ๋ผ์šฐ์ €๋‚˜ DOM๊ณผ๋Š” ๊ด€๋ จ์ด ์—†๋‹ค๋Š” ๊ฒƒ์„ ๋ถ„๋ช…ํžˆ ํ•œ๋‹ค. React๊ฐ€ ๋ Œ๋”๋งํ•  ์ˆ˜ ์žˆ๋Š” ๋” ๋งŽ์€ ํ™˜๊ฒฝ์„ ๊ตฌ์ถ•ํ•˜๊ธฐ ์œ„ํ•ด, React ํŒ€์€ ์ฃผ React ํŒจํ‚ค์ง€๋ฅผ react์™€ react-dom ๋‘ ๊ฐœ๋กœ ๋‚˜๋ˆŒ ๊ณ„ํš์„ ์„ธ์› ๋‹ค. ์ด๋Š” React๊ณผ React Native์˜ ์›น ๋ฒ„์ „ ๊ฐ„์— ๊ณต์œ ํ•  ์ˆ˜ ์žˆ๋Š” ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ž‘์„ฑํ•˜๋Š” ๊ธธ์„ ์—ด์–ด์ฃผ์—ˆ๋‹ค.

  98. React ๋ผ๋ฒจ ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    ํ‘œ์ค€ for ์†์„ฑ์„ ์‚ฌ์šฉํ•˜์—ฌ ํ…์ŠคํŠธ ์ž…๋ ฅ์— ๋ฐ”์ธ๋“œ๋œ <label> ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ๋ Œ๋”๋งํ•˜๋ ค๊ณ  ํ•˜๋ฉด, ํ•ด๋‹น ์†์„ฑ์ด ์—†๋Š” HTML์ด ์ƒ์„ฑ๋˜๊ณ  ์ฝ˜์†”์— ๊ฒฝ๊ณ ๊ฐ€ ์ธ์‡„๋œ๋‹ค.

    <label for={'user'}>{'User'}</label>
    <input type={'text'} id={'user'} />

    for๋Š” JavaScript์—์„œ ์˜ˆ์•ฝ๋œ ํ‚ค์›Œ๋“œ์ด๋ฏ€๋กœ, ๋Œ€์‹  htmlFor์„ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค.

    <label htmlFor={'user'}>{'User'}</label>
    <input type={'text'} id={'user'} />
  99. ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์ธ๋ผ์ธ ์Šคํƒ€์ผ ๊ฐ์ฒด๋ฅผ ๊ฒฐํ•ฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    ์ผ๋ฐ˜์ ์ธ React์—์„œ ์‚ฌ์šฉํ•˜๋Š” spread ์—ฐ์‚ฐ์ž.

     <button style={{...styles.panel.button, ...styles.panel.submitButton}}>{'Submit'}</button>

    React Native๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ๋ฐฐ์—ด ํ‘œ๊ธฐ๋ฒ•์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

    <button style={[styles.panel.button, styles.panel.submitButton]}>{'Submit'}</button>
  100. ๋ธŒ๋ผ์šฐ์ € ํฌ๊ธฐ๋ฅผ ์กฐ์ •ํ•  ๋•Œ ๋ทฐ๋ฅผ ๋ฆฌ๋ Œ๋”๋งํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    componentDidMount()์—์„œ resize ์ด๋ฒคํŠธ๋ฅผ ์ˆ˜์‹ ํ•˜๋ฉด, ํฌ๊ธฐ(๋„ˆ๋น„ ๋ฐ ๋†’์ด)๋ฅผ ์—…๋ฐ์ดํŠธ ํ•  ์ˆ˜ ์žˆ๋‹ค. componentWillUnmount() ๋ฉ”์„œ๋“œ์—์„œ ๋ฆฌ์Šค๋„ˆ๋ฅผ ์ œ๊ฑฐํ•ด์•ผ ํ•œ๋‹ค.

    class WindowDimensions extends React.Component {
      constructor(props){
        super(props);
        this.updateDimensions = this.updateDimensions.bind(this);
      }
       
      componentWillMount() {
        this.updateDimensions()
      }
    
      componentDidMount() {
        window.addEventListener('resize', this.updateDimensions)
      }
    
      componentWillUnmount() {
        window.removeEventListener('resize', this.updateDimensions)
      }
    
      updateDimensions() {
        this.setState({width: window.innerWidth, height: window.innerHeight})
      }
    
      render() {
        return <span>{this.state.width} x {this.state.height}</span>
      }
    }
  101. setState()์™€ replaceState() ๋ฉ”์„œ๋“œ์˜ ์ฐจ์ด์ ์€?

    setState()๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ํ˜„์žฌ state์™€ ์ด์ „ state๊ฐ€ ๋ณ‘ํ•ฉ๋œ๋‹ค. replaceState()๋Š” ํ˜„์žฌ state๋ฅผ ๋ฒ„๋ฆฌ๊ณ  ์‚ฌ์šฉ์ž๊ฐ€ ๋„ฃ์€ state๋กœ ๋ฐ”๊พผ๋‹ค. Usually ์–ด๋–ค ์ด์œ ๋กœ ์ด์ „์˜ ๋ชจ๋“  ํ‚ค๋ฅผ ์ œ๊ฑฐํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์•„๋‹ˆ๋ฉด setState()๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. replaceState()๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋Œ€์‹  setState()์—์„œ state๋ฅผ false/null๋กœ ์„ค์ •ํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

  102. state ๋ณ€๊ฒฝ์„ ์ธ์ง€ํ•˜๋Š” ๋ฐฉ๋ฒ•?

    state๊ฐ€ ๋ณ€๊ฒฝ๋˜๋ฉด ๋‹ค์Œ์˜ ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์„œ๋“œ๊ฐ€ ํ˜ธ์ถœ๋œ๋‹ค. ์ œ๊ณต๋œ state์™€ props ๊ฐ’์„ ํ˜„์žฌ state, props์™€ ๋น„๊ตํ•˜์—ฌ ์˜๋ฏธ ์žˆ๋Š” ๊ฒƒ์ด ๋ณ€๊ฒฝ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

    componentWillUpdate(object nextProps, object nextState)
    componentDidUpdate(object prevProps, object prevState)
    
  103. React state์—์„œ ๋ฐฐ์—ด ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ์ œ๊ฑฐํ•˜๋Š” ๊ถŒ์žฅ ๋ฐฉ๋ฒ•์€?

    ๋” ๋‚˜์€ ๋ฐฉ๋ฒ•์€ Array.prototype.filter() ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

    ์˜ˆ๋ฅผ ๋“ค์–ด, state๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๊ธฐ ์œ„ํ•œ removeItem() ๋ฉ”์„œ๋“œ๋ฅผ ์ƒ์„ฑํ•ด๋ณด์ž

    removeItem(index) {
      this.setState({
        data: this.state.data.filter((item, i) => i !== index)
      })
    }
  104. HTML ๋ Œ๋”๋ง์—†์ด React๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‚˜?

    ์ตœ์‹ ๋ฒ„์ „ (>=16.2)์—์„œ ๊ฐ€๋Šฅํ•˜๋‹ค. ๊ฐ€๋Šฅํ•œ ์˜ต์…˜์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

    render() {
      return false
    }
    render() {
      return null
    }
    render() {
      return []
    }
    render() {
      return <React.Fragment></React.Fragment>
    }
    render() {
      return <></>
    }

    undefined ๋ฐ˜ํ™˜์€ ์ž‘๋™ํ•˜์ง€ ์•Š๋Š”๋‹ค

  105. React์—์„œ JSON์„ ์ด์˜๊ฒŒ ์ถœ๋ ฅํ•˜๋Š” ๋ฐฉ๋ฒ•?

    <pre> ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ JSON.stringify()์˜ ์„œ์‹์ด ์œ ์ง€๋˜๋„๋ก ํ•  ์ˆ˜ ์žˆ๋‹ค.

    const data = { name: 'John', age: 42 }
    
    class User extends React.Component {
      render() {
        return (
          <pre>
            {JSON.stringify(data, null, 2)}
          </pre>
        )
      }
    }
    
    React.render(<User />, document.getElementById('container'))
  106. React์—์„œ props๋ฅผ ์—…๋ฐ์ดํŠธํ•  ์ˆ˜ ์—†๋Š” ์ด์œ ๋Š”?

    React ์ฒ ํ•™์€ props๊ฐ€ ๋ถˆ๋ณ€์ด๊ณ  ํ•˜ํ–ฅ์‹์ด์–ด์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค. ์ฆ‰, ๋ถ€๋ชจ๋Š” ๋ชจ๋“  props ๊ฐ’์„ ์ž์‹์—๊ฒŒ ๋ณด๋‚ผ ์ˆ˜ ์žˆ์ง€๋งŒ, ์ž์‹์€ ๋ฐ›์€ props๋ฅผ ์ˆ˜์ •ํ•  ์ˆ˜ ์—†๋‹ค.

  107. ํŽ˜์ด์ง€ ๋กœ๋“œ ์‹œ input ์—˜๋ฆฌ๋จผํŠธ์— ํฌ์ปค์Šค๋ฅผ ์ฃผ๋Š” ๋ฐฉ๋ฒ•์€?

    input ์—˜๋ฆฌ๋จผํŠธ์— ๋Œ€ํ•œ ref๋ฅผ ์ƒ์„ฑํ•˜๊ณ  componentDidMount()์—์„œ ์ด๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

    class App extends React.Component{
      componentDidMount() {
        this.nameInput.focus()
      }
    
      render() {
        return (
          <div>
            <input
              defaultValue={'Won\'t focus'}
            />
            <input
              ref={(input) => this.nameInput = input}
              defaultValue={'Will focus'}
            />
          </div>
        )
      }
    }
    
    ReactDOM.render(<App />, document.getElementById('app'))
  108. state์—์„œ ๊ฐ์ฒด๋ฅผ ์—…๋ฐ์ดํŠธ ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์€?

    1. state์™€ ๋ณ‘ํ•ฉ ํ•  ๊ฐ์ฒด๊ฐ€ ์žˆ๋Š” setState()๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค.

      • Object.assign()๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ์ฒด์˜ ๋ณต์‚ฌ๋ณธ์„ ๋งŒ๋“ ๋‹ค:

        const user = Object.assign({}, this.state.user, { age: 42 })
        this.setState({ user })
      • spread ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

        const user = { ...this.state.user, age: 42 }
        this.setState({ user })
    2. setState()๋ฅผ ํ•จ์ˆ˜์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•œ๋‹ค.

      this.setState(prevState => ({
        user: {
          ...prevState.user,
          age: 42
        }
      }))
  109. ์™œ ํ•จ์ˆ˜๊ฐ€ setState() ๊ฐ์ฒด๋ณด๋‹ค ์„ ํ˜ธ๋˜๋Š”๊ฐ€?

    React๋Š” ์—ฌ๋Ÿฌ setState() ํ˜ธ์ถœ์„ ์„ฑ๋Šฅ ํ–ฅ์ƒ์„ ์œ„ํ•ด ๋‹จ์ผ ์—…๋ฐ์ดํŠธ๋กœ ์ผ๊ด„์ฒ˜๋ฆฌํ•œ๋‹ค. this.props์™€ this.state๊ฐ€ ๋น„๋™๊ธฐ์ ์œผ๋กœ ์—…๋ฐ์ดํŠธ๋  ์ˆ˜ ์žˆ์Œ์œผ๋กœ ๋‹ค์Œ state๋ฅผ ๊ณ„์‚ฐํ•  ๋•Œ ํ•ด๋‹น ๊ฐ’์„ ์‹ ๋ขฐํ•ด์„œ๋Š” ์•ˆ ๋œ๋‹ค.

    counter ์˜ˆ์ œ๋Š” ์˜ˆ์ƒ๋Œ€๋กœ ์—…๋ฐ์ดํŠธ๋˜์ง€ ์•Š๋Š”๋‹ค.

    // Wrong
    this.setState({
      counter: this.state.counter + this.props.increment,
    })

    ์„ ํ˜ธ๋˜๋Š” ์ ‘๊ทผ๋ฒ•์€ ๊ฐ์ฒด๊ฐ€ ์•„๋‹Œ ํ•จ์ˆ˜๋กœ setState()๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ์ด ํ•จ์ˆ˜๋Š” ์ฒซ ๋ฒˆ์งธ ์ธ์ˆ˜๋กœ ์ด์ „ state๋ฅผ ๋ฐ›๊ณ  ๋‘ ๋ฒˆ์งธ ์ธ์ˆ˜๋กœ ์—…๋ฐ์ดํŠธ๊ฐ€ ์ ์šฉ๋œ props๋ฅผ ๋ฐ›๋Š”๋‹ค.

    // Correct
    this.setState((prevState, props) => ({
      counter: prevState.counter + props.increment
    }))
  110. ๋ธŒ๋ผ์šฐ์ € ๋Ÿฐํƒ€์ž„์— React ๋ฒ„์ „์„ ์–ด๋–ป๊ฒŒ ์•Œ ์ˆ˜ ์žˆ๋‚˜?

    React.version์„ ์‚ฌ์šฉํ•ด์„œ ๋ฒ„์ „์„ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค.

    const REACT_VERSION = React.version
    
    ReactDOM.render(
      <div>{`React version: ${REACT_VERSION}`}</div>,
      document.getElementById('app')
    )
  111. create-react-app์— polyfill์„ ํฌํ•จ์‹œํ‚ค๋Š” ๋ฐฉ๋ฒ•์€?

    1. core-js์—์„œ ์ˆ˜๋™์œผ๋กœ ๊ฐ€์ ธ์˜ค๊ธฐ

      polyfills.js์™€ ๊ฐ™์€ ํŒŒ์ผ์„ ๋งŒ๋“ค๊ณ  root index.js ํŒŒ์ผ์—์„œ importํ•œ๋‹ค. npm install core-js ๋˜๋Š” yarn add core-js๋ฅผ ์‹คํ–‰ํ•˜๊ณ  ํŠน์ • ํ•„์ˆ˜ ๊ธฐ๋Šฅ์„ importํ•œ๋‹ค.

      import 'core-js/fn/array/find'
      import 'core-js/fn/array/includes'
      import 'core-js/fn/number/is-nan'
    2. Polyfill ์„œ๋น„์Šค๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ:

      ์ด ์ค„์„ index.html์— ์ถ”๊ฐ€, polyfill.io CDN์„ ์‚ฌ์šฉํ•˜์—ฌ ์‚ฌ์šฉ์ž ์ง€์ • ๋ธŒ๋ผ์šฐ์ € ์ „์šฉ polyfill์„ ๊ฒ€์ƒ‰ํ•œ๋‹ค.

      <script src='https://cdn.polyfill.io/v2/polyfill.min.js?features=default,Array.prototype.includes'></script>

      ์œ„์˜ ์Šคํฌ๋ฆฝํŠธ์—์„œ Array.prototype.includes ๊ธฐ๋Šฅ์€ ๊ธฐ๋ณธ ๊ธฐ๋Šฅ ์ง‘ํ•ฉ์— ํฌํ•จ๋˜์–ด ์žˆ์ง€ ์•Š์Œ์œผ๋กœ ๋ช…์‹œ์ ์œผ๋กœ ์š”์ฒญํ•ด์•ผ ํ•œ๋‹ค.

  112. create-react-app์—์„œ http ๋Œ€์‹  https๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•?

    HTTPS=true ์„ค์ •๋งŒ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค. package.json ์Šคํฌ๋ฆฝํŠธ ์„น์…˜์„ ํŽธ์ง‘ํ•  ์ˆ˜ ์žˆ๋‹ค.

    "scripts": {
      "start": "set HTTPS=true && react-scripts start"
    }

    ๋˜๋Š” set HTTPS=true && npm start๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ๋œ๋‹ค.

  113. create-react-app์—์„œ ์ƒ๋Œ€ ๊ฒฝ๋กœ ๊ฐ€์ ธ์˜ค๊ธฐ ์‚ฌ์šฉ์„ ํ”ผํ•˜๋Š” ๋ฐฉ๋ฒ•?

    ํ”„๋กœ์ ํŠธ ๋ฃจํŠธ์— .env๋ผ๋Š” ํŒŒ์ผ์„ ๋งŒ๋“ค๊ณ  ๊ฒฝ๋กœ๋ฅผ import ํ•˜๋ฉด ๋œ๋‹ค.

    NODE_PATH=src/app
    

    ๊ฐœ๋ฐœ ์„œ๋ฒ„๋ฅผ ๋‹ค์‹œ ์‹œ์ž‘ํ•˜๋ฉด, ์ƒ๋Œ€ ๊ฒฝ๋กœ ์—†์ด src/app ๋‚ด๋ถ€์˜ ๋‚ด์šฉ์„ import ํ•  ์ˆ˜ ์žˆ๋‹ค.

  114. React Router์šฉ Google ์›น ๋กœ๊ทธ ๋ถ„์„์„ ์ถ”๊ฐ€ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    history ๊ฐ์ฒด์— ๋ฆฌ์Šค๋„ˆ๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ๊ฐ๊ฐ์˜ ํŽ˜์ด์ง€ view๋ฅผ ๊ธฐ๋กํ•œ๋‹ค.

    history.listen(function (location) {
      window.ga('set', 'page', location.pathname + location.search)
      window.ga('send', 'pageview', location.pathname + location.search)
    })
  115. ๋งค ์ดˆ๋งˆ๋‹ค ์ปดํฌ๋„ŒํŠธ๋ฅผ ์—…๋ฐ์ดํŠธ ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    ๋ณ€๊ฒฝ์„ ๊ฐ์ง€ํ•˜๋ ค๋ฉด setInterval()์„ ์‚ฌ์šฉํ•ด์•ผ ํ•˜์ง€๋งŒ ์˜ค๋ฅ˜ ๋ฐ ๋ฉ”๋ชจ๋ฆฌ ๋ˆ„์ˆ˜๋ฅผ ๋ฐฉ์ง€ํ•˜๋ ค๋ฉด ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋งˆ์šดํŠธ ํ•ด์ œ๋  ๋•Œ ํƒ€์ด๋จธ๋ฅผ ์ง€์›Œ์•ผ ํ•œ๋‹ค.

    componentDidMount() {
      this.interval = setInterval(() => this.setState({ time: Date.now() }), 1000)
    }
    
    componentWillUnmount() {
      clearInterval(this.interval)
    }
  116. React์—์„œ ์ธ๋ผ์ธ ์Šคํƒ€์ผ์— ๋ฒค๋” ์ ‘๋‘์‚ฌ๋Š” ์–ด๋–ป๊ฒŒ ์ ์šฉํ•˜๋‚˜?

    React๋Š” ๋ฒค๋” ์ ‘๋‘์‚ฌ๋ฅผ ์ž๋™์œผ๋กœ ์ ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค. ๋ฒค๋” ์ ‘๋‘์‚ฌ๋ฅผ ์ˆ˜๋™์œผ๋กœ ์ถ”๊ฐ€ํ•ด์•ผ ํ•œ๋‹ค.

    <div style={{
      transform: 'rotate(90deg)',
      WebkitTransform: 'rotate(90deg)', // note the capital 'W' here
      msTransform: 'rotate(90deg)' // 'ms' is the only lowercase vendor prefix
    }} />
  117. React์™€ ES6๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ฐ€์ ธ์˜ค๊ณ  ๋‚ด๋ณด๋‚ด๋Š” ๋ฐฉ๋ฒ•์€?

    ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋‚ด๋ณด๋‚ด๋ ค๋ฉด default๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

    import React from 'react'
    import User from 'user'
    
    export default class MyProfile extends React.Component {
      render(){
        return (
          <User type="customer">
            //...
          </User>
        )
      }
    }

    export ์ง€์ •์ž๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด MyProfile์ด ๋ฉค๋ฒ„๊ฐ€ ๋˜์–ด ์ด ๋ชจ๋“ˆ๋กœ ๋‚ด๋ณด๋‚ผ ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๋‹ค๋ฅธ ์ปดํฌ๋„ŒํŠธ์— ์ด๋ฆ„์„ ์–ธ๊ธ‰ํ•˜์ง€ ์•Š๊ณ ๋„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๋‹ค.

  118. React ์ปดํฌ๋„ŒํŠธ ์ด๋ฆ„์ด ๋Œ€๋ฌธ์ž๋กœ ์‹œ์ž‘ํ•ด์•ผ ํ•˜๋Š” ์ด์œ ๋Š”?

    JSX์—์„œ ์†Œ๋ฌธ์ž ํƒœ๊ทธ ์ด๋ฆ„์€ HTML ํƒœ๊ทธ๋กœ ๊ฐ„์ฃผํ•œ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์ ์œผ๋กœ ํ‘œ์‹œ๋œ ๋Œ€๋ฌธ์ž ๋ฐ ์†Œ๋ฌธ์ž ํƒœ๊ทธ ์ด๋ฆ„(์†์„ฑ ์ ‘๊ทผ์ž)์€ ์—†๋‹ค.

    1. <component />๋Š” React.createElement('component')๋กœ ์ปดํŒŒ์ผ๋œ๋‹ค. (i.e, HTML tag)
    2. <obj.component />๋Š” React.createElement(obj.component)๋กœ ์ปดํŒŒ์ผ๋œ๋‹ค.
    3. <Component />๋Š” React.createElement(Component)๋กœ ์ปดํŒŒ์ผ๋œ๋‹ค.
  119. ์ปดํฌ๋„ŒํŠธ ์ƒ์„ฑ์ž๋Š” ์™œ ํ•œ ๋ฒˆ๋งŒ ๋ถˆ๋ฆฌ๋‚˜?

    React์˜ reconciliation ์•Œ๊ณ ๋ฆฌ์ฆ˜์—์„œ๋Š” ์ •๋ฐ˜๋Œ€ ์ •๋ณด๊ฐ€ ์—†๋‹ค๊ณ  ๊ฐ€์ •ํ•˜๋Š”๋ฐ, ์‚ฌ์šฉ์ž ์ง€์ • ์ปดํฌ๋„ŒํŠธ๊ฐ€ ํ›„์† ๋ Œ๋”๋ง์˜ ๊ฐ™์€ ์œ„์น˜์— ๋‚˜ํƒ€๋‚˜๋ฉด, ์ด์ „ ์ปดํฌ๋„ŒํŠธ์™€ ๋™์ผ ํ•˜๋ฏ€๋กœ ์ด์ „ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒˆ๋กœ ์ž‘์„ฑํ•˜์ง€ ์•Š๊ณ  ๋‹ค์‹œ ์‚ฌ์šฉํ•œ๋‹ค.

  120. React์—์„œ ์ƒ์ˆ˜๋ฅผ ์ •์˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    ES7 static ํ•„๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ƒ์ˆ˜๋ฅผ ์ •์˜ํ•  ์ˆ˜ ์žˆ๋‹ค.

    class MyComponent extends React.Component {
      static DEFAULT_PAGINATION = 10
    }

    Static fields๋Š” Class Fields ์Šคํ…Œ์ด์ง€ 3 ์ œ์•ˆ์˜ ์ผ๋ถ€์ด๋‹ค.

  121. React์—์„œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ฐฉ์‹์œผ๋กœ ํด๋ฆญ ์ด๋ฒคํŠธ๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๋Š” ๋ฐฉ๋ฒ•์€?

    ref prop๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ฝœ๋ฐฑ์„ ํ†ตํ•ด ๊ธฐ๋ณธ HTMLInputElement ๊ฐ์ฒด์— ๋Œ€ํ•œ ์ฐธ์กฐ๋ฅผ ๊ฐ€์ ธ์™€์„œ, ์ฐธ์กฐ๋ฅผ ํด๋ž˜์Šค ์†์„ฑ์œผ๋กœ ์ €์žฅํ•œ ๋‹ค์Œ, ํ•ด๋‹น ์ฐธ์กฐ์˜ HTMLElement.click ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ์—์„œ ํด๋ฆญ์„ ํŠธ๋ฆฌ๊ฑฐ ํ•  ์ˆ˜ ์žˆ๋‹ค.

    1. render ๋ฉ”์„œ๋“œ ์•ˆ์—์„œ ref๋ฅผ ๋งŒ๋“ ๋‹ค.

      <input ref={input => this.inputElement = input} />
    2. ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ์— ํด๋ฆญ ์ด๋ฒคํŠธ๋ฅผ ์ ์šฉํ•œ๋‹ค.

      this.inputElement.click()
  122. async/await๋ฅผ ํ‰๋ฒ”ํ•œ React์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‚˜?

    React์—์„œ async/await์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด, Babel ๋ฐ transform-async-to-generator ํ”Œ๋Ÿฌ๊ทธ์ธ์ด ํ•„์š”ํ•˜๋‹ค. React Native๋Š” Babel๊ณผ ๋ณ€๊ฒฝ ์„ธํŠธ๋ฅผ ๊ตฌ์„ฑํ•ด์•ผ ํ•œ๋‹ค.

  123. React์˜ ์ผ๋ฐ˜์ ์ธ ํด๋” ๊ตฌ์กฐ๋Š”?

    React ํ”„๋กœ์ ํŠธ ํŒŒ์ผ ๊ตฌ์กฐ๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ ์‚ฌ์šฉ๋˜๋Š” 2๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค.

    1. ๊ธฐ๋Šฅ ๋˜๋Š” ๊ฒฝ๋กœ๋ณ„๋กœ ๊ทธ๋ฃนํ™”

      ํ”„๋กœ์ ํŠธ๋ฅผ ๊ตฌ์กฐํ™”ํ•˜๋Š” ์ผ๋ฐ˜์ ์ธ ๋ฐฉ๋ฒ•์˜ ํ•˜๋‚˜๋Š” ๊ธฐ๋Šฅ์ด๋‚˜ ๊ฒฝ๋กœ๋ณ„๋กœ ๊ทธ๋ฃนํ™”๋œ CSS, JS, ๋ฐ ํ…Œ์ŠคํŠธ๋ฅผ ํ•จ๊ป˜ ๋ฐฐ์น˜ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

      common/
      โ”œโ”€ Avatar.js
      โ”œโ”€ Avatar.css
      โ”œโ”€ APIUtils.js
      โ””โ”€ APIUtils.test.js
      feed/
      โ”œโ”€ index.js
      โ”œโ”€ Feed.js
      โ”œโ”€ Feed.css
      โ”œโ”€ FeedStory.js
      โ”œโ”€ FeedStory.test.js
      โ””โ”€ FeedAPI.js
      profile/
      โ”œโ”€ index.js
      โ”œโ”€ Profile.js
      โ”œโ”€ ProfileHeader.js
      โ”œโ”€ ProfileHeader.css
      โ””โ”€ ProfileAPI.js
      
    2. ํŒŒ์ผ ํƒ€์ž…์œผ๋กœ ๊ทธ๋ฃนํ™”

      ํ”„๋กœ์ ํŠธ๋ฅผ ๊ตฌ์กฐํ™”ํ•˜๋Š” ๋‹ค๋ฅธ ๋ณดํŽธ์ ์ธ ๋ฐฉ๋ฒ•์€ ์œ ์‚ฌํ•œ ํŒŒ์ผ๋ผ๋ฆฌ ๊ทธ๋ฃนํ™”ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

      api/
      โ”œโ”€ APIUtils.js
      โ”œโ”€ APIUtils.test.js
      โ”œโ”€ ProfileAPI.js
      โ””โ”€ UserAPI.js
      components/
      โ”œโ”€ Avatar.js
      โ”œโ”€ Avatar.css
      โ”œโ”€ Feed.js
      โ”œโ”€ Feed.css
      โ”œโ”€ FeedStory.js
      โ”œโ”€ FeedStory.test.js
      โ”œโ”€ Profile.js
      โ”œโ”€ ProfileHeader.js
      โ””โ”€ ProfileHeader.css
      
  124. ์ธ๊ธฐ ์• ๋‹ˆ๋ฉ”์ด์…˜ ํŒจํ‚ค์ง€๋Š”?

    React Transition Group๊ณผ React Motion์ด React ์ƒํƒœ๊ณ„์—์„œ ๊ฐ€์žฅ ์ธ๊ธฐ ์žˆ๋Š” ์• ๋‹ˆ๋ฉ”์ด์…˜ ํŒจํ‚ค์ง€์ด๋‹ค.

  125. ์Šคํƒ€์ผ ๋ชจ๋“ˆ์˜ ์ด์ ์€?

    ์ปดํฌ๋„ŒํŠธ์—์„œ ์Šคํƒ€์ผ ๊ฐ’์„ ํ•˜๋“œ ์ฝ”๋”ฉ ํ•˜๋Š” ๊ฒƒ์€ ์ข‹์ง€ ์•Š๋‹ค. ๋‹ค๋ฅธ UI ์ปดํฌ๋„ŒํŠธ์—์„œ ์‚ฌ์šฉ๋  ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ๋Š” ๊ฐ’์€ ์ž์ฒด ๋ชจ๋“ˆ๋กœ ๋ฝ‘์•„๋‚ด์•ผ ํ•œ๋‹ค.

    ์˜ˆ๋ฅผ ๋“ค์–ด, ์ด๋Ÿฌํ•œ ์Šคํƒ€์ผ์€ ๋ณ„๋„์˜ ์ปดํฌ๋„ŒํŠธ๋กœ ๋ฝ‘์•„๋‚ผ ์ˆ˜ ์žˆ๋‹ค.

    export const colors = {
      white,
      black,
      blue
    }
    
    export const space = [
      0,
      8,
      16,
      32,
      64
    ]

    ๊ทธ๋Ÿฐ ๋‹ค์Œ ๋‹ค๋ฅธ ์ปดํฌ๋„ŒํŠธ์—์„œ ๊ฐœ๋ณ„์ ์œผ๋กœ ๊ฐ€์ ธ์˜จ๋‹ค.

    import { space, colors } from './styles'
  126. ์ธ๊ธฐ์žˆ๋Š” React-๊ด€๋ จ linters๋Š”?

    ESLint๋Š” ์ธ๊ธฐ ์žˆ๋Š” JavaScript linter์ด๋‹ค. ํŠน์ • ์ฝ”๋“œ ์Šคํƒ€์ผ์„ ๋ถ„์„ํ•  ์ˆ˜ ์žˆ๋Š” ํ”Œ๋Ÿฌ๊ทธ์ธ์ด ์žˆ๋‹ค. React์—์„œ ๊ฐ€์žฅ ์ผ๋ฐ˜์ ์œผ๋กœ ์‚ฌ์šฉ๋˜๋Š” ํŒจํ‚ค์ง€ ์ค‘ ํ•˜๋‚˜๋Š” eslint-plugin-react npm ํŒจํ‚ค์ง€๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ, ๋ฐ˜๋ณต์ž์—๊ฒŒ ์žˆ๋Š” ํ‚ค๋ถ€ํ„ฐ ์ „์ฒด prop ํƒ€์ž…๊นŒ์ง€ ๊ฒ€์‚ฌํ•˜๋Š” ๊ทœ์น™์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ€์žฅ ์ข‹์€ ์‚ฌ๋ก€๋ฅผ ์—ฌ๋Ÿฌ ๋ฒˆ ํ™•์ธํ•  ๊ฒƒ์ด๋‹ค. ๋˜ ๋‹ค๋ฅธ ์ธ๊ธฐ ์žˆ๋Š” ํ”Œ๋Ÿฌ๊ทธ์ธ์€ eslint-plugin-jsx-a11y๋กœ, ์ ‘๊ทผ์„ฑ๊ณผ ๊ด€๋ จ๋œ ์ผ๋ฐ˜์ ์ธ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋Š” ๋ฐ ๋„์›€์ด ๋œ๋‹ค. JSX๋Š” ์ผ๋ฐ˜ HTML๊ณผ ์•ฝ๊ฐ„ ๋‹ค๋ฅธ ๊ตฌ๋ฌธ์„ ์ œ๊ณตํ•˜๊ธฐ ๋•Œ๋ฌธ์— alt ํ…์ŠคํŠธ๋‚˜ tabindex์™€ ๊ด€๋ จ๋œ ๋ฌธ์ œ๋Š” ์ผ๋ฐ˜์ ์ธ ํ”Œ๋Ÿฌ๊ทธ์ธ์œผ๋กœ ์ฐพ์•„๋‚ผ ์ˆ˜ ์—†๋‹ค.

  127. AJAX ํ˜ธ์ถœํ•˜๋Š” ๋ฐฉ๋ฒ•๊ณผ ์–ด๋Š ์ปดํฌ๋„ŒํŠธ ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์„œ๋“œ์—์„œ AJAX ํ˜ธ์ถœ์„ ํ•ด์•ผํ•˜๋‚˜?

    Axios, jQuery AJAX ๋ฐ ๋ธŒ๋ผ์šฐ์ € ๋‚ด์žฅ fetch์™€ ๊ฐ™์€ AJAX libraries๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. componentDidMount() ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์„œ๋“œ์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์™€์•ผ ํ•œ๋‹ค. ๋ฐ์ดํ„ฐ๋ฅผ ๊ฒ€์ƒ‰ํ•  ๋•Œ setState()๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์—…๋ฐ์ดํŠธ ํ•  ์ˆ˜ ์žˆ๋‹ค.

    ์˜ˆ๋ฅผ ๋“ค์–ด, ์ง์› ๋ชฉ๋ก์€ API์—์„œ ๊ฐ€์ ธ์™€์„œ ๋กœ์ปฌ state์— ์„ค์ •ํ•œ๋‹ค.

    class MyComponent extends React.Component {
      constructor(props) {
        super(props)
        this.state = {
          employees: [],
          error: null
        }
      }
    
      componentDidMount() {
        fetch('https://api.example.com/items')
          .then(res => res.json())
          .then(
            (result) => {
              this.setState({
                employees: result.employees
              })
            },
            (error) => {
              this.setState({ error })
            }
          )
      }
    
      render() {
        const { error, employees } = this.state
        if (error) {
          return <div>Error: {error.message}</div>;
        } else {
          return (
            <ul>
              {employees.map(item => (
                <li key={employee.name}>
                  {employee.name}-{employees.experience}
                </li>
              ))}
            </ul>
          )
        }
      }
    }
  128. render props๋ž€?

    Render Props๋Š” ๊ฐ’์ด ํ•จ์ˆ˜์ธ prop์„ ์‚ฌ์šฉํ•˜์—ฌ ์ปดํฌ๋„ŒํŠธ ๊ฐ„ ์ฝ”๋“œ๋ฅผ ๊ณต์œ ํ•˜๋Š” ๊ฐ„๋‹จํ•œ ๊ธฐ์ˆ ์ด๋‹ค. ์•„๋ž˜์˜ ์ปดํฌ๋„ŒํŠธ๋Š” React ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” render props๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

    <DataProvider render={data => (
      <h1>{`Hello ${data.target}`}</h1>
    )}/>

    React Router์™€ DownShift ๊ฐ™์€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ์ด ํŒจํ„ด์„ ์‚ฌ์šฉํ•œ๋‹ค.

React Router

  1. React Router๋ž€?

    React Router๋Š” React ์œ„์— ๊ตฌ์ถ•๋œ ๊ฐ•๋ ฅํ•œ ๋ผ์šฐํŒ… ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ URL์„ ํŽ˜์ด์ง€์— ํ‘œ์‹œ๋œ ๋‚ด์šฉ๊ณผ ๋™๊ธฐํ™”๋œ ์ƒํƒœ๋กœ ์œ ์ง€ํ•˜๋ฉด์„œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์ƒˆ๋กœ์šด ํ™”๋ฉด๊ณผ ํ”Œ๋กœ์šฐ๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋‹ค.

  2. React Router๊ฐ€ history ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€ ๋‹ค๋ฅธ์ ์€?

    React Router๋Š” ๋ธŒ๋ผ์šฐ์ €์˜ window.history์™€ ๋ธŒ๋ผ์šฐ์ € ํ•ด์‰ฌ ๊ธฐ๋ก์˜ ์ƒํ˜ธ ์ž‘์šฉ์„ ์ฒ˜๋ฆฌํ•˜๋Š” history ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๊ฐ์‹ธ๋Š” ๋ž˜ํผ์ด๋‹ค. ๋˜ํ•œ ๋ชจ๋ฐ”์ผ ํžˆ์Šคํ† ๋ฆฌ๋ฅผ ์ œ๊ณตํ•˜์—ฌ ๋ชจ๋ฐ”์ผ ์•ฑ ๊ฐœ๋ฐœ(React Native) ๋ฐ Node ๋‹จ์œ„ ํ…Œ์ŠคํŠธ์™€ ๊ฐ™์ด ๊ธ€๋กœ๋ฒŒ ํžˆ์Šคํ† ๋ฆฌ๊ฐ€ ์—†๋Š” ํ™˜๊ฒฝ์— ์œ ์šฉํ•˜๋‹ค.

  3. Router v4์˜ <Router> ์ปดํฌ๋„ŒํŠธ๋Š” ๋ฌด์—‡์ธ๊ฐ€?

    React Router v4๋Š” ์•„๋ž˜์˜ 3๊ฐœ์˜ <Router> ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ œ๊ณตํ•œ๋‹ค.

    1. <BrowserRouter>
    2. <HashRouter>
    3. <MemoryRouter>

    ์œ„์˜ ์ปดํฌ๋„ŒํŠธ๋Š” browser, hash ๋ฐ memory history ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•œ๋‹ค. React Router v4๋Š” router ๊ฐ์ฒด์˜ ์ปจํ…์ŠคํŠธ๋ฅผ ํ†ตํ•ด์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋ผ์šฐํ„ฐ์™€ ์—ฐ๊ฒฐ๋œ history ์ธ์Šคํ„ด์Šค์˜ ์†์„ฑ๊ณผ ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•œ๋‹ค.

  4. history์˜ push(), place()` ๋ฉ”์„œ๋“œ์˜ ๋ชฉ์ ์€?

    history ์ธ์Šคํ„ด์Šค์—๋Š” ํƒ์ƒ‰์„ ์œ„ํ•œ ๋‘๊ฐ€์ง€ ๋ฉ”์„œ๋“œ๊ฐ€ ์žˆ๋‹ค.

    1. push()
    2. replace()

    history๋ฅผ ๋ฐฉ๋ฌธํ•œ ์œ„์น˜์˜ ๋ฐฐ์—ด๋กœ ์ƒ๊ฐํ•˜๋ฉด push()๋Š” ๋ฐฐ์—ด์— ์ƒˆ ์œ„์น˜๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ , replace()๋Š” ๋ฐฐ์—ด์˜ ํ˜„์žฌ ์œ„์น˜๋ฅผ ์ƒˆ๋กœ์šด ์œ„์น˜๋กœ ๋ฐ”๊พผ๋‹ค.

  5. React Router v4๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ฐฉ์‹์œผ๋กœ ์–ด๋–ป๊ฒŒ ํƒ์ƒ‰ํ•˜๋‚˜?

    ์ปดํฌ๋„ŒํŠธ๋‚ด์—์„œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ฐฉ์‹์˜ ๋ผ์šฐํŒ… / ํƒ์ƒ‰์„ ์ˆ˜ํ–‰ํ•˜๋Š” ์„ธ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค.

    1. withRouter() ๊ณ ์ฐจ ํ•จ์ˆ˜ ์‚ฌ์šฉ

      withRouter() ๊ณ ์ฐจ ํ•จ์ˆ˜๋Š” history ๊ฐ์ฒด๋ฅผ ์ปดํฌ๋„ŒํŠธ์˜ prop๋กœ ์‚ฝ์ž…๋œ๋‹ค. ์ด ๊ฐ์ฒด๋Š” push() ๋ฐ replace() ๋ฉ”์„œ๋“œ๋ฅผ ์ œ๊ณตํ•œ๋‹ค.

      import { withRouter } from 'react-router-dom' // this also works with 'react-router-native'
      
      const Button = withRouter(({ history }) => (
        <button
          type='button'
          onClick={() => { history.push('/new-location') }}
        >
          {'Click Me!'}
        </button>
      ))
    2. <Route> ์ปดํฌ๋„ŒํŠธ์™€ ๋ Œ๋”๋ง props ํŒจํ„ด ์‚ฌ์šฉ

      The <Route> ์ปดํฌ๋„ŒํŠธ๋Š” withRouter()์™€ ๊ฐ™์€ prop์„ ์ „๋‹ฌํ•˜๋ฏ€๋กœ, history prop์„ ํ†ตํ•ด history ๋ฉ”์„œ๋“œ์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋‹ค.

      import { Route } from 'react-router-dom'
      
      const Button = () => (
        <Route render={({ history }) => (
          <button
            type='button'
            onClick={() => { history.push('/new-location') }}
          >
            {'Click Me!'}
          </button>
        )} />
      )
    3. context ์‚ฌ์šฉ

      ์ด ์˜ต์…˜์€ ๊ถŒ์žฅ๋˜์ง€ ์•Š์œผ๋ฉฐ ๋ถˆ์•ˆ์ •ํ•œ API๋กœ ์ฒ˜๋ฆฌ๋œ๋‹ค.

      const Button = (props, context) => (
        <button
          type='button'
          onClick={() => {
            context.history.push('/new-location')
          }}
        >
          {'Click Me!'}
        </button>
      )
      
      Button.contextTypes = {
        history: React.PropTypes.shape({
          push: React.PropTypes.func.isRequired
        })
      }
  6. React Router v4์—์„œ ์ฟผ๋ฆฌ ๋งค๊ฐœ ๋ณ€์ˆ˜๋ฅผ ์–ป๋Š” ๋ฐฉ๋ฒ•์€?

    ๋‹ค๋ฅธ ๊ตฌํ˜„์„ ์ง€์›ํ•˜๊ธฐ ์œ„ํ•ด ์ˆ˜๋…„ ๋™์•ˆ ์‚ฌ์šฉ์ž ์š”์ฒญ์ด ์žˆ์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ์ฟผ๋ฆฌ ๋ฌธ์ž์—ด์„ ๊ตฌ๋ฌธ ๋ถ„์„ํ•˜๋Š” ๊ธฐ๋Šฅ์€ React Router v4์—์„œ ์ œ๊ฑฐ๋˜์—ˆ๋‹ค. ๊ทธ๋ž˜์„œ ์‚ฌ์šฉ์ž๊ฐ€ ์›ํ•˜๋Š” ๊ตฌํ˜„์„ ์„ ํƒํ•˜๋„๋ก ๊ฒฐ์ •๋˜์—ˆ๋‹ค. ๊ถŒ์žฅ๋˜๋Š” ๋ฐฉ๋ฒ•์€ ์ฟผ๋ฆฌ ๋ฌธ์ž์—ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

    const queryString = require('query-string');
    const parsed = queryString.parse(props.location.search);

    ๋„ค์ดํ‹ฐ๋ธŒ๋ฅผ ์›ํ•œ๋‹ค๋ฉด URLSearchParams๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

    const params = new URLSearchParams(props.location.search)
    const foo = params.get('name')

    IE11์—์„œ๋Š” polyfill๋ฅผ ์‚ฌ์šฉํ•ด์•ผํ•œ๋‹ค.

  7. ์™œ "Router may have only one child element"๋ผ๋Š” ๊ฒฝ๊ณ  ๋ฉ”์‹œ์ง€๊ฐ€ ๋‚˜์˜ค๋‚˜?

    <Switch>๋Š” ๋ผ์šฐํ„ฐ๋ฅผ ๋…์ ์ ์œผ๋กœ ๋ Œ๋”๋งํ•œ๋‹ค๋Š” ์ ์—์„œ ๊ณ ์œ ํ•˜๋ฏ€๋กœ <Switch> ๋ธ”๋ก์— ๋ผ์šฐํ„ฐ๋ฅผ ๊ฐ์‹ธ์•ผ ํ•œ๋‹ค.

    ๋จผ์ € Switch๋ฅผ import ํ•ด์ค€๋‹ค.

    import { Switch, Router, Route } from 'react-router'

    ๊ทธ๋Ÿฐ ๋‹ค์Œ <Switch> ๋ธ”๋ก ๋‚ด์—์„œ ๊ฒฝ๋กœ๋ฅผ ์ •์˜ํ•œ๋‹ค.

    <Router>
      <Switch>
        <Route {/* ... */} />
        <Route {/* ... */} />
      </Switch>
    </Router>
  8. React Router v4์˜ history.push ๋ฉ”์„œ๋“œ์— ๋งค๊ฐœ ๋ณ€์ˆ˜๋ฅผ ์ „๋‹ฌํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    ๋„ค๋น„๊ฒŒ์ด์…˜ํ•˜๋Š” ๋™์•ˆ history ๊ฐ์ฒด์— props๋ฅผ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋‹ค.

    this.props.history.push({
      pathname: '/template',
      search: '?name=sudheer',
      state: { detail: response.data }
    })

    search ์†์„ฑ์€ push() ๋ฉ”์„œ๋“œ์—์„œ ์ฟผ๋ฆฌ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ „๋‹ฌํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋œ๋‹ค.

  9. default ๋˜๋Š” NotFound ํŽ˜์ด์ง€ ๊ตฌํ˜„ ๋ฐฉ๋ฒ•?

    <Switch>๋Š” ์ผ์น˜ํ•˜๋Š” ์ฒซ ๋ฒˆ์งธ ํ•˜์œ„ <Route>๋ฅผ ๋ Œ๋”๋งํ•œ๋‹ค. ๊ฒฝ๋กœ๊ฐ€ ์—†๋Š” <Route>๋Š” ํ•ญ์ƒ ์ผ์น˜ํ•œ๋‹ค. ๋”ฐ๋ผ์„œ ์•„๋ž˜์™€ ๊ฐ™์€ ๊ฒฝ๋กœ ์†์„ฑ์„ ์‚ญ์ œํ•˜๋ฉด ๋œ๋‹ค.

    <Switch>
      <Route exact path="/" component={Home}/>
      <Route path="/user" component={User}/>
      <Route component={NotFound} />
    </Switch>
  10. React Router v4์—์„œ history๋ฅผ ์–ป๋Š” ๋ฐฉ๋ฒ•์€

    1. history ๊ฐ์ฒด๋ฅผ export ํ•œ ํ›„ ํ”„๋กœ์ ํŠธ ์ „์ฒด๋ฅผ import ํ•˜๋Š” ๋ชจ๋“ˆ์„ ์ž‘์„ฑํ•˜๋ฉด ๋œ๋‹ค.

      ์˜ˆ๋ฅผ ๋“ค์–ด, history.js ํŒŒ์ผ์„ ๋งŒ๋“ ๋‹ค.

      import { createBrowserHistory } from 'history'
      
      export default createBrowserHistory({
        /* pass a configuration object here if needed */
      })
    2. ๊ธฐ๋ณธ์œผ๋กœ ์ œ๊ณต๋˜๋Š” ๋ผ์šฐํ„ฐ ๋Œ€์‹  <Router> ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค. index.js ํŒŒ์ผ ๋‚ด์—์„œ history.js๋ฅผ import ํ•œ๋‹ค.

      import { Router } from 'react-router-dom'
      import history from './history'
      import App from './App'
      
      ReactDOM.render((
        <Router history={history}>
          <App />
        </Router>
      ), holder)
    3. ๋‚ด์žฅ๋œ history ๊ฐ์ฒด์™€ ์œ ์‚ฌํ•œ history ๊ฐ์ฒด์˜ push ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

      // some-other-file.js
      import history from './history'
      
      history.push('/go-here')
  11. ๋กœ๊ทธ์ธ ํ›„ ์ž๋™ ๋ฆฌ๋””๋ ‰์…˜์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    react-router ํŒจํ‚ค์ง€๋Š” React Router์—์„œ <Redirect> ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ œ๊ณตํ•œ๋‹ค. <Redirect>์„ ๋ Œ๋”๋งํ•˜๋ฉด ์ƒˆ๋กœ์šด ์œ„์น˜๋กœ ์ด๋™ํ•œ๋‹ค. ์„œ๋ฒ„ ์‚ฌ์ด๋“œ ๋ฆฌ๋””๋ ‰์…˜๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ƒˆ๋กœ์šด ์œ„์น˜๋Š” history ์Šคํƒ์˜ ํ˜„์žฌ ์œ„์น˜๋ฅผ ๋ฌด์‹œํ•œ๋‹ค.

    import React, { Component } from 'react'
    import { Redirect } from 'react-router'
    
    export default class LoginComponent extends Component {
      render() {
        if (this.state.isLoggedIn === true) {
          return <Redirect to="/your/redirect/page" />
        } else {
          return <div>{'Login Please'}</div>
        }
      }
    }

React Internationalization

  1. What is React Intl?

    The React Intl library makes internalization in React straightforward, with off-the-shelf components and an API that can handle everything from formatting strings, dates, and numbers, to pluralization. React Intl is part of FormatJS which provides bindings to React via its components and API.

  2. What are the main features of React Intl?

    1. Display numbers with separators.
    2. Display dates and times correctly.
    3. Display dates relative to "now".
    4. Pluralize labels in strings.
    5. Support for 150+ languages.
    6. Runs in the browser and Node.
    7. Built on standards.
  3. What are the two ways of formatting in React Intl?

    The library provides two ways to format strings, numbers, and dates: react components or an API.

    <FormattedMessage
      id={'account'}
      defaultMessage={'The amount is less than minimum balance.'}
    />
    const messages = defineMessages({
      accountMessage: {
        id: 'account',
        defaultMessage: 'The amount is less than minimum balance.',
      }
    })
    
    formatMessage(messages.accountMessage)
  4. How to use <FormattedMessage> as placeholder using React Intl?

    The <Formatted... /> components from react-intl return elements, not plain text, so they can't be used for placeholders, alt text, etc. In that case, you should use lower level API formatMessage(). You can inject the intl object into your component using injectIntl() higher-order component and then format the message using formatMessage() available on that object.

    import React from 'react'
    import { injectIntl, intlShape } from 'react-intl'
    
    const MyComponent = ({ intl }) => {
      const placeholder = intl.formatMessage({id: 'messageId'})
      return <input placeholder={placeholder} />
    }
    
    MyComponent.propTypes = {
      intl: intlShape.isRequired
    }
    
    export default injectIntl(MyComponent)
  5. How to access current locale with React Intl?

    You can get the current locale in any component of your application using injectIntl():

    import { injectIntl, intlShape } from 'react-intl'
    
    const MyComponent = ({ intl }) => (
      <div>{`The current locale is ${intl.locale}`}</div>
    )
    
    MyComponent.propTypes = {
      intl: intlShape.isRequired
    }
    
    export default injectIntl(MyComponent)
  6. How to format date using React Intl?

    The injectIntl() higher-order component will give you access to the formatDate() method via the props in your component. The method is used internally by instances of FormattedDate and it returns the string representation of the formatted date.

    import { injectIntl, intlShape } from 'react-intl'
    
    const stringDate = this.props.intl.formatDate(date, {
      year: 'numeric',
      month: 'numeric',
      day: 'numeric'
    })
    
    const MyComponent = ({intl}) => (
      <div>{`The formatted date is ${stringDate}`}</div>
    )
    
    MyComponent.propTypes = {
      intl: intlShape.isRequired
    }
    
    export default injectIntl(MyComponent)

React Testing

  1. What is Shallow Renderer in React testing?

    Shallow rendering is useful for writing unit test cases in React. It lets you render a component one level deep and assert facts about what its render method returns, without worrying about the behavior of child components, which are not instantiated or rendered.

    For example, if you have the following component:

    function MyComponent() {
      return (
        <div>
          <span className={'heading'}>{'Title'}</span>
          <span className={'description'}>{'Description'}</span>
        </div>
      )
    }

    Then you can assert as follows:

    import ShallowRenderer from 'react-test-renderer/shallow'
    
    // in your test
    const renderer = new ShallowRenderer()
    renderer.render(<MyComponent />)
    
    const result = renderer.getRenderOutput()
    
    expect(result.type).toBe('div')
    expect(result.props.children).toEqual([
      <span className={'heading'}>{'Title'}</span>,
      <span className={'description'}>{'Description'}</span>
    ])
  2. What is TestRenderer package in React?

    This package provides a renderer that can be used to render components to pure JavaScript objects, without depending on the DOM or a native mobile environment. This package makes it easy to grab a snapshot of the platform view hierarchy (similar to a DOM tree) rendered by a ReactDOM or React Native without using a browser or jsdom.

    import TestRenderer from 'react-test-renderer'
    
    const Link = ({page, children}) => <a href={page}>{children}</a>
    
    const testRenderer = TestRenderer.create(
      <Link page={'https://www.facebook.com/'}>{'Facebook'}</Link>
    )
    
    console.log(testRenderer.toJSON())
    // {
    //   type: 'a',
    //   props: { href: 'https://www.facebook.com/' },
    //   children: [ 'Facebook' ]
    // }
  3. What is the purpose of ReactTestUtils package?

    ReactTestUtils are provided in the with-addons package and allow you to perform actions against a simulated DOM for the purpose of unit testing.

  4. What is Jest?

    Jest is a JavaScript unit testing framework created by Facebook based on Jasmine and provides automated mock creation and a jsdom environment. It's often used for testing components.

  5. What are the advantages of Jest over Jasmine?

    There are couple of advantages compared to Jasmine:

    • Automatically finds tests to execute in your source code.
    • Automatically mocks dependencies when running your tests.
    • Allows you to test asynchronous code synchronously.
    • Runs your tests with a fake DOM implementation (via jsdom) so that your tests can be run on the command line.
    • Runs tests in parallel processes so that they finish sooner.
  6. Give a simple example of Jest test case

    Let's write a test for a function that adds two numbers in sum.js file:

    const sum = (a, b) => a + b
    
    export default sum

    Create a file named sum.test.js which contains actual test:

    import sum from './sum'
    
    test('adds 1 + 2 to equal 3', () => {
      expect(sum(1, 2)).toBe(3)
    })

    And then add the following section to your package.json:

    {
      "scripts": {
        "test": "jest"
      }
    }

    Finally, run yarn test or npm test and Jest will print a result:

    $ yarn test
    PASS ./sum.test.js
    โœ“ adds 1 + 2 to equal 3 (2ms)

React Redux

  1. flux๋ž€?

    Flux๋Š” ์ „ํ†ต์ ์ธ MVC ํŒจํ„ด์˜ ๋Œ€์ฒดํ’ˆ์œผ๋กœ ์‚ฌ์šฉ๋˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋””์ž์ธ ํŒจ๋Ÿฌ๋‹ค์ž„์ด๋‹ค. ์ด๊ฒƒ์€ ๋‹จ์ˆœํžˆ ํ”„๋ ˆ์ž„์›Œํฌ๋‚˜ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์•„๋‹ˆ๋ผ React์™€ ๋‹จ๋ฐฉํ–ฅ ๋ฐ์ดํ„ฐ ํ๋ฆ„์˜ ๊ฐœ๋…์„ ๋ณด์™„ํ•˜๋Š” ์ƒˆ๋กœ์šด ์ข…๋ฅ˜์˜ ์•„ํ‚คํ…์ฒ˜์ด๋‹ค. Facebook์€ React๋กœ ์ž‘์—…ํ•  ๋•Œ ์ด ํŒจํ„ด์„ ๋‚ด๋ถ€์ ์œผ๋กœ ์‚ฌ์šฉํ•œ๋‹ค.

    ๋””์ŠคํŒจ์ฒ˜ ๊ฐ„ ์›Œํฌํ”Œ๋กœ์šฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ณ ์œ ํ•œ ์ž…๋ ฅ ๋ฐ ์ถœ๋ ฅ์œผ๋กœ ๊ตฌ์„ฑ ์š”์†Œ๋ฅผ ์ €์žฅํ•˜๊ณ  ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

    flux

  2. Redux๋ž€?

    Redux๋Š” Flux ๋””์ž์ธ ํŒจํ„ด์„ ๊ธฐ๋ฐ˜์œผ๋กœํ•˜๋Š” JavaScript ์•ฑ์„ ์œ„ํ•œ ์˜ˆ์ธก ๊ฐ€๋Šฅํ•œ ์ƒํƒœ ์ปจํ…Œ์ด๋„ˆ์ด๋‹ค. Redux๋Š” React์™€ ํ•จ๊ป˜ ๋˜๋Š” ๋‹ค๋ฅธ ๋ทฐ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€ ํ•จ๊ป˜ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ํฌ๊ธฐ๊ฐ€ ์ž‘๊ณ (2kB ์ •๋„) ์ข…์†์„ฑ์ด ์—†๋‹ค.

  3. Redux์˜ ํ•ต์‹ฌ ์›์น™์€?

    Redux๋Š” ์„ธ ๊ฐ€์ง€ ๊ธฐ๋ณธ์›์น™์„ ๋”ฐ๋ฅธ๋‹ค.

    1. ์ง„์‹ค์˜ ๋‹จ์ผ ์†Œ์Šค(Single source of truth): ์ „์ฒด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ state๋Š” ๋‹จ์ผ ์ €์žฅ์†Œ ๋‚ด Object Tree์— ์ €์žฅ๋œ๋‹ค. ๋‹จ์ผ state ํŠธ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์‹œ๊ฐ„์ด ์ง€๋‚จ์— ๋”ฐ๋ฅธ ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ์ถ”์ ํ•˜๊ณ  ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์„ ๋””๋ฒ„๊ทธ ๋˜๋Š” ๊ฒ€์‚ฌํ•˜๊ธฐ์— ์‰ฝ๋‹ค.
    2. State๋Š” ์ฝ๊ธฐ ์ „์šฉ: state๋ฅผ ๋ณ€๊ฒฝํ•˜๋Š” ์œ ์ผํ•œ ๋ฐฉ๋ฒ•์€ ๋ฌด์Šจ ์ผ์ด ์žˆ์—ˆ๋Š”์ง€ ์„ค๋ช…ํ•œ ๊ฐ์ฒด์ธ action์„ ๋‚ด๋ณด๋‚ด๋Š” ๊ฒƒ์ด๋‹ค. ๋ทฐ๋‚˜ ๋„คํŠธ์›Œํฌ ์ฝœ๋ฐฑ์ด state์— ์ง์ ‘ ์“ฐ์ง€ ์•Š๋Š”๋‹ค.
    3. Changes are made with pure functions: ์ž‘์—…์— ์˜ํ•ด state ํŠธ๋ฆฌ๊ฐ€ ๋ณ€ํ™˜๋˜๋Š” action์„ ์ง€์ •ํ•˜๋ ค๋ฉด reducer๋ฅผ ์ž‘์„ฑํ•ด์•ผ ํ•œ๋‹ค. Reducers๋Š” ์ด์ „์˜ state์™€ action์„ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ์‚ฌ์šฉํ•˜๊ณ , ๋‹ค์Œ์˜ state๋ฅผ return ํ•˜๋Š” ์ˆœ์ˆ˜ํ•จ์ˆ˜์ด๋‹ค.
  4. Flux์™€ ๋น„๊ตํ•œ Redux์˜ ๋‹จ์ ์€?

    ๋‹จ์  ๋Œ€์‹ ์— Flux๋ฅผ ํ†ตํ•ด Redux์„ ์‚ฌ์šฉํ•˜๋ฉด ๋”๋Ÿฝํžˆ๋Š” ์ผ์ด ๊ฑฐ์˜ ์—†๋‹ค.

    1. Mutation์„ ํ”ผํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ฐฐ์›Œ์•ผ ํ•œ๋‹ค.: Flux๋Š” ๋ฐ์ดํ„ฐ ๋ณ€๊ฒฝ์— ๋Œ€ํ•ด ์˜๊ฒฌ์ด ๋งŽ์ง€ ์•Š์ง€๋งŒ, Redux๋Š” mutation์„ ์ข‹์•„ํ•˜์ง€ ์•Š์œผ๋ฉฐ Redux๋ฅผ ๋ณด์™„ํ•˜๋Š” ๋งŽ์€ ํŒจํ‚ค์ง€๋Š” state๋ฅผ ์ ˆ๋Œ€๋กœ ๋ณ€๊ฒฝํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์„ ๊ฐ€์ •ํ•œ๋‹ค. redux-immutable-state-invariant, Immutable.js์™€ ๊ฐ™์€ ๊ฐœ๋ฐœ ์ „์šฉ ํŒจํ‚ค์ง€๋ฅผ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ ํŒ€์—๊ฒŒ ๋ณ€๊ฒฝํ•˜์ง€ ์•Š๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋„๋ก ์ง€์‹œํ•˜์—ฌ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
    2. packages๋ฅผ ์‹ ์ค‘ํ•˜๊ฒŒ ์„ ํƒํ•ด์•ผ ํ•œ๋‹ค.: Flux๋Š” ์‹คํ–‰ ์ทจ์†Œ / ๋‹ค์‹œ ์‹คํ–‰, ์ง€์†์„ฑ ๋˜๋Š” ์–‘์‹๊ณผ ๊ฐ™์€ ๋ฌธ์ œ๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ํ•ด๊ฒฐํ•˜๋ ค๊ณ  ์‹œ๋„ํ•˜์ง€ ์•Š์ง€๋งŒ, Redux์—๋Š” ๋ฏธ๋“ค์›จ์–ด ๋ฐ ์ €์žฅ์†Œ ํ–ฅ์ƒ๊ธฐ์™€ ๊ฐ™์€ ์ต์Šคํ…์…˜์ด ์žˆ์œผ๋ฉฐ ํ’๋ถ€ํ•œ ์—์ฝ” ์‹œ์Šคํ…œ์„ ์ƒ์„ฑํ–ˆ๋‹ค.
    3. ์•„์ง ์ข‹์€ ํ๋ฆ„ ํ†ตํ•ฉ์€ ์—†๋‹ค.: Flux๋Š” ํ˜„์žฌ Redux๊ฐ€ ์ง€์›ํ•˜์ง€ ์•Š๋Š” ๋งค์šฐ ์ธ์ƒ์ ์ธ ์ •์  ์œ ํ˜• ๊ฒ€์‚ฌ๋ฅผ ์ˆ˜ํ–‰ ํ•  ์ˆ˜ ์žˆ๋‹ค.
  5. mapStateToProps()๊ณผ mapDispatchToProps()์˜ ์ฐจ์ด์ ์€?

    mapStateToProps()๋Š” ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋‹ค๋ฅธ ์ปดํฌ๋„ŒํŠธ์— ์˜ํ•ด ์—…๋ฐ์ดํŠธ๋œ state๋ฅผ ๋ฐ›์•„์˜ค๋Š”๋ฐ ๋„์™€์ฃผ๋Š” ์œ ํ‹ธ๋ฆฌํ‹ฐ์ด๋‹ค.

    const mapStateToProps = (state) => {
      return {
        todos: getVisibleTodos(state.todos, state.visibilityFilter)
      }
    }

    mapDispatchToProps()๋Š” ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์‘์šฉํ”„๋กœ๊ทธ๋žจ state ๋ณ€๊ฒฝ์„ ์ผ์œผํ‚ค๋Š” dispatching action ์ด๋ฒคํŠธ๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๋Š”๋ฐ ๋„์™€์ฃผ๋Š” ์œ ํ‹ธ๋ฆฌํ‹ฐ์ด๋‹ค.

    const mapDispatchToProps = (dispatch) => {
      return {
        onTodoClick: (id) => {
          dispatch(toggleTodo(id))
        }
      }
    }

    mapDispatchToProps์— ๋Œ€ํ•ด์„œ ํ•ญ์ƒ "๊ฐ์ฒด ์•ฝ์‹(object shorthand)" ์–‘์‹์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ์ถ”์ฒœํ•œ๋‹ค.

    Redux๋Š” (โ€ฆargs) => dispatch(onTodoClick(โ€ฆargs))์™€ ๊ฐ™์€ ๋‹ค๋ฅธ ํ•จ์ˆ˜๋กœ ๋ž˜ํ•‘ํ•˜๊ณ  ํ•ด๋‹น ๋ž˜ํผ ํ•จ์ˆ˜๋ฅผ โ€‹โ€‹์ปดํฌ๋„ŒํŠธ์˜ prop์œผ๋กœ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค.

     const mapDispatchToProps = ({
       onTodoClick
     })
  6. reducer์—์„œ action์„ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋‚˜?

    reducer ๋‚ด์—์„œ action์„ ์ „๋‹ฌํ•˜๋Š” ๊ฒƒ์€ anti-pattern์ด๋‹ค. ๋ฆฌ๋“€์„œ๋Š” ์‚ฌ์ด๋“œ ์ดํŽ™ํŠธ(side effects) ๊ฐ€ ์—†์–ด์•ผ ํ•œ๋‹ค. ๋‹จ์ˆœํžˆ action payload๋ฅผ ์†Œํ™”ํ•˜๊ณ  ์ƒˆ๋กœ์šด state ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. reducer ๋‚ด์— ๋ฆฌ์Šค๋„ˆ๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  action์„ ์ „๋‹ฌํ•˜๋ฉด, ์—ฐ์‡„์ ์œผ๋กœ action ๋ฐ ๋‹ค๋ฅธ ์‚ฌ์ด๋“œ ์ดํŽ™ํŠธ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค.

  7. ์ปดํฌ๋„ŒํŠธ ์™ธ๋ถ€์˜ Redux store์— ์ ‘๊ทผํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    createStore()๋กœ ์ž‘์„ฑ๋œ ๋ชจ๋“ˆ์—์„œ store๋ฅผ ๋‚ด๋ณด๋‚ด๋ฉด ๋œ๋‹ค. ๋˜ํ•œ, ์ „์—ญ window ๊ฐ์ฒด๋ฅผ ์˜ค์—ผ์‹œํ‚ค์ง€ ์•Š์•„์•ผ ํ•œ๋‹ค.

    store = createStore(myReducer)
    
    export default store
  8. MVW ํŒจํ„ด์˜ ๋‹จ์ ์€ ๋ฌด์—‡์ธ๊ฐ€?

    1. DOM ์กฐ์ž‘์€ ๋น„์šฉ์ด ๋งŽ์ด ๋“ค์–ด์„œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ๋Š๋ฆฌ๊ณ  ๋น„ํšจ์œจ์ ์œผ๋กœ ์ž‘๋™ํ•˜๊ฒŒ ํ•œ๋‹ค.
    2. ์ˆœํ™˜ ์ข…์†์„ฑ์œผ๋กœ ์ธํ•ด, ๋ชจ๋ธ๊ณผ ๋ทฐ๋ฅผ ์ค‘์‹ฌ์œผ๋กœ ํ•œ ๋ณต์žกํ•œ ๋ชจ๋ธ์ด ์ƒ์„ฑ๋œ๋‹ค.
    3. ๊ตฌ๊ธ€ ๊ฐ™์€ ๊ณต๋™์ž‘์—… ์‘์šฉํ”„๋กœ๊ทธ๋žจ์—์„œ๋Š” ๋งŽ์€ ๋ฐ์ดํ„ฐ ๋ณ€๊ฒฝ์ด ๋ฐœ์ƒํ•œ๋‹ค.
    4. ์—„์ฒญ ๋งŽ์€ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•˜์ง€ ์•Š๊ณ ์„œ๋Š” ์‰ฝ๊ฒŒ ๋˜๋Œ๋ฆด ๋ฐฉ๋ฒ•์ด ์—†๋‹ค.
  9. Redux์™€ RxJS์˜ ๋น„์Šทํ•œ ์ ์€?

    ์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ค์€ ๋‹ค๋ฅธ ๋ชฉ์ ์„ ๊ฐ€์ง„๋‹ค๋Š” ์ ์—์„œ ๋งค์šฐ ๋‹ค๋ฅด์ง€๋งŒ, ๋ชจํ˜ธํ•œ ์œ ์‚ฌ์ ์„ ๊ฐ€์ง„๋‹ค.

    Redux๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ „์ฒด์—์„œ state๋ฅผ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ๋„๊ตฌ์ด๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ UI ์•„ํ‚คํ…์ฒ˜๋กœ ์‚ฌ์šฉ๋œ๋‹ค. ์ด๊ฒƒ์„ Angular์˜ ์ ˆ๋ฐ˜์— ํ•ด๋‹นํ•˜๋Š” ๋Œ€์•ˆ์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜์ž. RxJS๋Š” reactive ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ JavaScript์—์„œ ๋น„๋™๊ธฐ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋„๊ตฌ๋กœ ์‚ฌ์šฉ๋œ๋‹ค. ์ด๊ฒƒ์„ Promises์˜ ๋Œ€์•ˆ์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜์ž. Redux๋Š” store๊ฐ€ reactive ํ•˜๊ธฐ ๋•Œ๋ฌธ์— Reactive ํŒจ๋Ÿฌ๋‹ค์ž„์„ ์‚ฌ์šฉํ•œ๋‹ค. Store๋Š” ๋ฉ€๋ฆฌ์„œ ํ–‰๋™์„ ๊ด€์ฐฐํ•˜๊ณ  ์Šค์Šค๋กœ ๋ณ€ํ™”์‹œํ‚จ๋‹ค. RxJS๋Š” ๋˜ํ•œ Reactive ํŒจ๋Ÿฌ๋‹ค์ž„์„ ์‚ฌ์šฉํ•˜์ง€๋งŒ, ์•„ํ‚คํ…์ฒ˜๋ฅผ ๋Œ€์ฒดํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹Œ ํŒจํ„ด์„ ๋‹ฌ์„ฑํ•˜๊ธฐ ์œ„ํ•œ ๊ธฐ๋ณธ ์„ค๊ณ„ ๋ธ”๋ก, Observables๋ฅผ ์ œ๊ณตํ•œ๋‹ค.

  10. ๋กœ๋“œ ์‹œ์ ์— action์„ ์ „๋‹ฌํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

`componentDidMount()` ๋ฉ”์„œ๋“œ์—์„œ action์„ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๊ณ  `render()` ๋ฉ”์„œ๋“œ์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 ```javascript
 class App extends Component {
   componentDidMount() {
     this.props.fetchData()
   }

   render() {
     return this.props.isLoaded
       ? <div>{'Loaded'}</div>
       : <div>{'Not Loaded'}</div>
   }
 }

 const mapStateToProps = (state) => ({
   isLoaded: state.isLoaded
 })

 const mapDispatchToProps = { fetchData }

 export default connect(mapStateToProps, mapDispatchToProps)(App)
 ```
  1. React Redux์—์„œ connect()๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    container์—์„œ store๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ๋‹ค์Œ ๋‘ ๋‹จ๊ณ„๋ฅผ ์ˆ˜ํ–‰ํ•ด์•ผ ํ•œ๋‹ค.

    1. mapStateToProps() ์‚ฌ์šฉํ•˜๊ธฐ: store์˜ state ๋ณ€์ˆ˜๋ฅผ ์ง€์ •ํ•œ props์— ๋งคํ•‘ํ•œ๋‹ค

    2. ์œ„์˜ props์™€ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์—ฐ๊ฒฐํ•˜๊ธฐ: mapStateToProps ํ•จ์ˆ˜๋กœ ๋ฐ˜ํ™˜ํ•œ ๊ฐ์ฒด๊ฐ€ ์ปจํ…Œ์ด๋„ˆ์— ์—ฐ๊ฒฐ๋˜์–ด ์žˆ๋‹ค. react-redux์—์„œ connect()๋ฅผ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๋‹ค.

      import React from 'react'
      import { connect } from 'react-redux'
      
      class App extends React.Component {
        render() {
          return <div>{this.props.containerData}</div>
        }
      }
      
      function mapStateToProps(state) {
        return { containerData: state.data }
      }
      
      export default connect(mapStateToProps)(App)
  2. Redux์—์„œ state๋ฅผ ์žฌ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    combineReducers() ์œผ๋กœ ๋งŒ๋“ค์–ด์ง„ reducer์˜ action ์ฒ˜๋ฆฌ๋ฅผ ์œ„์ž„ํ•˜๋Š” root reducer ๋ฅผ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์ž‘์„ฑํ•ด์•ผ ํ•œ๋‹ค.

    ์˜ˆ๋ฅผ ๋“ค์–ด, USER_LOGOUT action ํ›„ ์ดˆ๊ธฐ state๋ฅผ ๋ฆฌํ„ดํ•˜๊ธฐ ์œ„ํ•ด rootReducer() ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ์•ผ ํ•œ๋‹ค. ์•Œ๋‹ค์‹œํ”ผ, reducer๋Š” action๊ณผ ๊ด€๊ณ„์—†์ด ์ฒซ ๋ฒˆ์งธ ์ธ์ˆ˜๋กœ undefined ๋กœ ํ˜ธ์ถœ๋  ๋•Œ ์ดˆ๊ธฐ ์ƒํƒœ๋ฅผ ๋ฐ˜ํ™˜ํ•ด์•ผ ํ•œ๋‹ค.

    const appReducer = combineReducers({
      /* your app's top-level reducers */
    })
    
    const rootReducer = (state, action) => {
      if (action.type === 'USER_LOGOUT') {
        state = undefined
      }
    
      return appReducer(state, action)
    }

    redux-persist๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ, storage๋ฅผ ์ •๋ฆฌํ•ด์•ผ ํ•  ์ˆ˜ ์žˆ๋‹ค. redux-persist ๋Š” state ์—”์ง„์„ storage ์—”์ง„์— ๋ณด๊ด€ํ•œ๋‹ค. ๋จผ์ €, ์ ์ ˆํ•œ storage ์—”์ง„์„ ๊ฐ€์ ธ์™€์„œ state ํ‚ค๋ฅผ ์ •์˜ํ•˜์ง€ ์•Š๊ณ  ์ •๋ฆฌํ•˜๊ธฐ ์ „์— state๋ฅผ ๊ตฌ๋ฌธ ๋ถ„์„ํ•ด์•ผ ํ•œ๋‹ค.

    const appReducer = combineReducers({
      /* your app's top-level reducers */
    })
    
    const rootReducer = (state, action) => {
      if (action.type === 'USER_LOGOUT') {
        Object.keys(state).forEach(key => {
          storage.removeItem(`persist:${key}`)
        })
    
        state = undefined
      }
    
      return appReducer(state, action)
    }
  3. Redux connect ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ์—์„œ at ๊ธฐํ˜ธ์˜ ๋ชฉ์ ์€?

    @ ๊ธฐํ˜ธ๋Š” ์‹ค์ œ๋กœ ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š”๋ฐ ์‚ฌ์šฉ๋˜๋Š” JavaScript ํ‘œํ˜„์‹์ด๋‹ค. ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋””์ž์ธ ํƒ€์ž„์— ํด๋ž˜์Šค์™€ ์†์„ฑ์— ์ฃผ์„์„ ๋‹ฌ๊ณ  ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

    ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ๊ณผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  Redux๋ฅผ ์„ค์ •ํ•˜๋Š” ์˜ˆ๋ฅผ ์‚ดํŽด๋ณด์ž.

    • ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ๊ฐ€ ์—†์„ ๊ฒฝ์šฐ:

      import React from 'react'
      import * as actionCreators from './actionCreators'
      import { bindActionCreators } from 'redux'
      import { connect } from 'react-redux'
      
      function mapStateToProps(state) {
        return { todos: state.todos }
      }
      
      function mapDispatchToProps(dispatch) {
        return { actions: bindActionCreators(actionCreators, dispatch) }
      }
      
      class MyApp extends React.Component {
        // ...define your main app here
      }
      
      export default connect(mapStateToProps, mapDispatchToProps)(MyApp)
    • ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ:

      import React from 'react'
      import * as actionCreators from './actionCreators'
      import { bindActionCreators } from 'redux'
      import { connect } from 'react-redux'
      
      function mapStateToProps(state) {
        return { todos: state.todos }
      }
      
      function mapDispatchToProps(dispatch) {
        return { actions: bindActionCreators(actionCreators, dispatch) }
      }
      
      @connect(mapStateToProps, mapDispatchToProps)
      export default class MyApp extends React.Component {
        // ...define your main app here
      }

    ์œ„์˜ ์˜ˆ์ œ๋“ค๋Š” ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ ์‚ฌ์šฉ์„ ์ œ์™ธํ•˜๊ณ ๋Š” ๊ฑฐ์˜ ๋น„์Šทํ•˜๋‹ค. ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ ๊ตฌ๋ฌธ์€ ์•„์ง JavaScript ๋Ÿฐํƒ€์ž„์— ๋‚ด์žฅ๋˜์–ด ์žˆ์ง€ ์•Š๋‹ค. ์‹คํ—˜ ์ค‘์ด๋ฉฐ ๋ณ€๊ฒฝ๋  ์ˆ˜ ์žˆ๋‹ค. ํ˜„์žฌ ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ ์ง€์›์„ ์œ„ํ•ด์„œ babel์„ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

  4. React context์™€ React Redux์˜ ์ฐจ์ด์ ์€?

    ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์— Context ๋ฅผ ๋ฐ”๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ ์„ค๊ณ„๋œ ์ค‘์ฒฉ๋œ ์ปดํฌ๋„ŒํŠธ์— ๋ฐ์ดํ„ฐ๋ฅผ ์ „๋‹ฌํ•˜๋Š” ๋ฐ ์œ ์šฉํ•˜๋‹ค. ๋ฐ˜๋ฉด Redux ๋Š” ํ›จ์”ฌ ๊ฐ•๋ ฅํ•˜๊ณ  Context API๊ฐ€ ์ œ๊ณตํ•˜์ง€ ์•Š๋Š” ๋งŽ์€ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•œ๋‹ค. ๋˜ํ•œ, React Redux ๋Š” ๋‚ด๋ถ€์ ์œผ๋กœ Context๋ฅผ ์‚ฌ์šฉํ•˜์ง€๋งŒ, ์ด ์‚ฌ์‹ค์„ public API์— ์•Œ๋ฆฌ์ง€ ์•Š๋Š”๋‹ค.

  5. Redux state ํ•จ์ˆ˜๊ฐ€ reducer๋ผ๊ณ  ๋ถˆ๋ฆฌ๋Š” ์ด์œ ๋Š”?

    Reducers๋Š” ํ•ญ์ƒ state์˜ ๋ˆ„์ ์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค(๋ชจ๋“  ์ด์ „๊ณผ ํ˜„์žฌ์˜ action์„ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•œ๋‹ค). ๊ทธ๋Ÿฌ๋ฏ€๋กœ, state๋ฅผ ์ค„์ด๋Š” ์—ญํ• ์„ ํ•œ๋‹ค. Redux reducer๊ฐ€ ํ˜ธ์ถœ๋  ๋•Œ๋งˆ๋‹ค state ๋ฐ action์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ „๋‹ฌ๋œ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ state๋Š” action์— ๋”ฐ๋ผ ๊ฐ์†(๋˜๋Š” ๋ˆ„์ )๋˜๊ณ  ๋‹ค์Œ state๊ฐ€ ๋ฐ˜ํ™˜๋œ๋‹ค. action ์ปฌ๋ ‰์…˜ ๋ฐ ๊ฒฐ๊ณผ์ ์ธ ์ตœ์ข… state๋ฅผ ์–ป๊ธฐ ์œ„ํ•ด ์ด๋Ÿฌํ•œ state๋ฅผ ์ˆ˜ํ–‰ํ•  store์˜ ์ดˆ๊ธฐ ์ƒํƒœ๋ฅผ ์ค„์ผ ์ˆ˜ ์žˆ๋‹ค.

  6. Redux์—์„œ AJAX๋ฅผ ์š”์ฒญํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    ๋น„๋™๊ธฐ action์„ ์ •์˜ํ•  ์ˆ˜ ์žˆ๋Š” redux-thunk ๋ฏธ๋“ค์›จ์–ด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

    fetch API ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํŠน์ • ๊ณ„์ •์„ AJAX ํ˜ธ์ถœ๋กœ ๊ฐ€์ ธ์˜ค๋Š” ์˜ˆ์‹œ๋ฅผ ๋“ค์–ด๋ณด์ž.

    export function fetchAccount(id) {
      return dispatch => {
        dispatch(setLoadingAccountState()) // Show a loading spinner
        fetch(`/account/${id}`, (response) => {
          dispatch(doneFetchingAccount()) // Hide loading spinner
          if (response.status === 200) {
            dispatch(setAccount(response.json)) // Use a normal function to set the received state
          } else {
            dispatch(someError)
          }
        })
      }
    }
    
    function setAccount(data) {
     return { type: 'SET_Account', data: data }
    }
  7. Redux store์— ๋ชจ๋“  ์ปดํฌ๋„ŒํŠธ์˜ state๋ฅผ ์œ ์ง€ํ•ด์•ผ ํ•˜๋‚˜?

    Redux store์— ๋ฐ์ดํ„ฐ๋ฅผ ์œ ์ง€ํ•˜๊ณ , ์ปดํฌ๋„ŒํŠธ ๋‚ด๋ถ€์— UI ๊ด€๋ จ state๋ฅผ ์œ ์ง€ํ•˜๋ฉด ๋œ๋‹ค.

  8. Redux store์— ์ ‘๊ทผํ•˜๋Š” ์˜ฌ๋ฐ”๋ฅธ ๋ฐฉ๋ฒ•์€?

    ์ปดํฌ๋„ŒํŠธ์—์„œ store์— ์ ‘๊ทผํ•˜๋Š” ๊ฐ€์žฅ ์ข‹์€ ๋ฐฉ๋ฒ•์€ connect() ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ธฐ์กด ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ฐ์‹ธ๋Š” ์ƒˆ๋กœ์šด ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒƒ์ด๋‹ค. ์ด๋Ÿฌํ•œ ํŒจํ„ด์„ Higher-Order Components ๋ผ๊ณ  ํ•˜๋ฉฐ, ์ผ๋ฐ˜์ ์œผ๋กœ React์—์„œ ์ปดํฌ๋„ŒํŠธ์˜ ๊ธฐ๋Šฅ์„ ํ™•์žฅํ•˜๋Š”๋ฐ ์„ ํ˜ธ๋˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. ์ด๋ฅผ ํ†ตํ•ด state ๋ฐ action ์ƒ์„ฑ์ž๋ฅผ ์ปดํฌ๋„ŒํŠธ์— ๋งคํ•‘ํ•˜๊ณ  store ์—…๋ฐ์ดํŠธ ์‹œ ์ž๋™์œผ๋กœ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋‹ค.

    connect๋ฅผ ์‚ฌ์šฉํ•œ <FilterLink> ์ปดํฌ๋„ŒํŠธ ์˜ˆ์‹œ๋ฅผ ๋ณด์ž.

    import { connect } from 'react-redux'
    import { setVisibilityFilter } from '../actions'
    import Link from '../components/Link'
    
    const mapStateToProps = (state, ownProps) => ({
      active: ownProps.filter === state.visibilityFilter
    })
    
    const mapDispatchToProps = (dispatch, ownProps) => ({
      onClick: () => dispatch(setVisibilityFilter(ownProps.filter))
    })
    
    const FilterLink = connect(
      mapStateToProps,
      mapDispatchToProps
    )(Link)
    
    export default FilterLink

    ์„ฑ๋Šฅ ์ตœ์ ํ™”๊ฐ€ ์ƒ๋‹นํžˆ ์ ๊ณ  ์ผ๋ฐ˜์ ์œผ๋กœ ๋ฒ„๊ทธ๊ฐ€ ๋ฐœ์ƒํ•  ๊ฐ€๋Šฅ์„ฑ์ด ์ž‘๊ธฐ ๋•Œ๋ฌธ์— Redux ๊ฐœ๋ฐœ์ž๋Š” ํ•ญ์ƒ Context API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ €์žฅ์†Œ์— ์ ‘๊ทผํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค๋Š” connect() ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.

    class MyComponent {
      someMethod() {
        doSomethingWith(this.context.store)
      }
    }
  9. React Redux์—์„œ ์ปดํฌ๋„ŒํŠธ์™€ ์ปจํ…Œ์ด๋„ˆ์˜ ์ฐจ์ด์ ์€?

    Component ๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ presentational ๋ถ€๋ถ„์„ ๋ฌ˜์‚ฌํ•˜๋Š” ํด๋ž˜์Šค ๋˜๋Š” ํ•จ์ˆ˜ํ˜• ์ปดํฌ๋„ŒํŠธ์ด๋‹ค.

    Container ๋Š” Redux store์— ์—ฐ๊ฒฐ๋œ ์ปดํฌ๋„ŒํŠธ์— ๋Œ€ํ•œ ๋น„๊ณต์‹ ์šฉ์–ด์ด๋‹ค. ์ปจํ…Œ์ด๋„ˆ๋Š” Redux state ์—…๋ฐ์ดํŠธ ๋ฐ dispatch action์„ ๊ตฌ๋…ํ•˜๋ฉฐ ์ผ๋ฐ˜์ ์œผ๋กœ DOM ์š”์†Œ๋ฅผ ๋ Œ๋”๋งํ•˜์ง€ ์•Š๋Š”๋‹ค. ๊ทธ๋“ค์€ presentational ์ž์‹ ์ปดํฌ๋„ŒํŠธ์— ๋ Œ๋”๋ง์„ ์œ„์ž„ํ•œ๋‹ค.

  10. Redux์—์„œ ์ƒ์ˆ˜์˜ ๋ชฉ์ ์€ ๋ฌด์—‡์ธ๊ฐ€?

    ์ƒ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด IDE๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ํ”„๋กœ์ ํŠธ ์ „์ฒด์—์„œ ํŠน์ • ๊ธฐ๋Šฅ์˜ ๋ชจ๋“  ์‚ฌ์šฉ๋ฒ•์„ ์‰ฝ๊ฒŒ ์ฐพ์„ ์ˆ˜ ์žˆ๋‹ค. ์˜คํƒ€๊ฐ™์€ ๊ฒฝ์šฐ ReferenceError ๋ฅผ ๋˜์ ธ์ฃผ์–ด ๋ฒ„๊ทธ ๋ฐœ์ƒ์„ ์‚ฌ์ „์— ๋ฐฉ์ง€ํ•œ๋‹ค.

    ๋ณดํ†ต ํ•˜๋‚˜์˜ ํŒŒ์ผ๋กœ ์ €์žฅํ•œ๋‹ค (constants.js ๋˜๋Š” actionTypes.js).

    export const ADD_TODO = 'ADD_TODO'
    export const DELETE_TODO = 'DELETE_TODO'
    export const EDIT_TODO = 'EDIT_TODO'
    export const COMPLETE_TODO = 'COMPLETE_TODO'
    export const COMPLETE_ALL = 'COMPLETE_ALL'
    export const CLEAR_COMPLETED = 'CLEAR_COMPLETED'

    Redux์—์„œ๋Š” ๋‘ ๊ณณ์—์„œ ์‚ฌ์šฉํ•œ๋‹ค.

    1. action์„ ์ž‘์„ฑํ•  ๋•Œ

      actions.js ์„ ๋ณด์ž.

      import { ADD_TODO } from './actionTypes';
      
      export function addTodo(text) {
        return { type: ADD_TODO, text }
      }
    2. reducer ์•ˆ์—์„œ

      reducer.js ๋ฅผ ๋งŒ๋“ค์–ด ๋ณด์ž.

      import { ADD_TODO } from './actionTypes'
      
      export default (state = [], action) => {
        switch (action.type) {
          case ADD_TODO:
            return [
              ...state,
              {
                text: action.text,
                completed: false
              }
            ];
          default:
            return state
        }
      }
  11. mapDispatchToProps()๋ฅผ ์ž‘์„ฑํ•˜๋Š” ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์€?

`mapDispatchToProps()`์—์„œ *action creators*๋ฅผ `dispatch()`์— ๋ฐ”์ธ๋”ฉํ•˜๋Š” ๋ช‡ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค. ๊ฐ€๋Šฅํ•œ ์˜ต์…˜์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

 ```javascript
 const mapDispatchToProps = (dispatch) => ({
  action: () => dispatch(action())
 })
 ```

 ```javascript
 const mapDispatchToProps = (dispatch) => ({
  action: bindActionCreators(action, dispatch)
 })
 ```

 ```javascript
 const mapDispatchToProps = { action }
 ```

์„ธ ๋ฒˆ์งธ ์˜ต์…˜์€ ์ฒซ ๋ฒˆ์งธ ์˜ต์…˜์˜ ์•ฝ์–ด์ด๋‹ค.
  1. mapStateToProps() ๊ณผ mapDispatchToProps() ์—์„œ ownProps ๋งค๊ฐœ ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    ownProps ๋งค๊ฐœ ๋ณ€์ˆ˜๊ฐ€ ์ง€์ •๋˜๋ฉด, React Redux๋Š” ์ปดํฌ๋„ŒํŠธ์— ์ „๋‹ฌ๋œ props๋ฅผ connect ํ•จ์ˆ˜๋กœ ์ „๋‹ฌํ•œ๋‹ค. ๋”ฐ๋ผ์„œ, ์—ฐ๊ฒฐ๋œ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ,

    import ConnectedComponent from './containers/ConnectedComponent';
    
    <ConnectedComponent user={'john'} />

    mapStateToProps()๊ณผ mapDispatchToProps() ํ•จ์ˆ˜ ๋‚ด์—์„œ ownProps ๋Š” ๊ฐ์ฒด๊ฐ€ ๋œ๋‹ค.

    { user: 'john' }

    ์ด ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ•ด๋‹น ํ•จ์ˆ˜์—์„œ ๋ฌด์—‡์„ ๋ฐ˜ํ™˜ํ• ์ง€ ๊ฒฐ์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

  2. Redux ์ตœ์ƒ์œ„ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    ๋Œ€๋ถ€๋ถ„์˜ ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์—๋Š” ์•„๋ž˜์™€ ๊ฐ™์€ ์—ฌ๋Ÿฌ ์ตœ์ƒ์œ„ ๋””๋ ‰ํ„ฐ๋ฆฌ๊ฐ€ ์žˆ๋‹ค.

    1. Components: Redux๋ฅผ ์ธ์‹ํ•˜์ง€ ๋ชปํ•˜๋Š” dumb ์ปดํฌ๋„ŒํŠธ์— ์‚ฌ์šฉ๋œ๋‹ค.
    2. Containers: Redux์— ์—ฐ๊ฒฐ๋œ smart ์ปดํฌ๋„ŒํŠธ์— ์‚ฌ์šฉ๋œ๋‹ค.
    3. Actions: ๋ชจ๋“  action creator์— ์‚ฌ์šฉ๋˜๋ฉฐ, ํŒŒ์ผ ์ด๋ฆ„์ด ์•ฑ์˜ ์ผ๋ถ€์ด๋‹ค.
    4. Reducers: ๋ชจ๋“  reducer์— ์‚ฌ์šฉ๋˜๋ฉฐ, ํŒŒ์ผ ์ด๋ฆ„์€ state ํ‚ค์ด๋‹ค.
    5. Store: store ์ดˆ๊ธฐํ™”์— ์‚ฌ์šฉ๋œ๋‹ค.

    ์ด ๊ตฌ์กฐ๋Š” ์ค‘์†Œ๊ทœ๋ชจ์˜ ์•ฑ์— ์ ํ•ฉํ•˜๋‹ค.

  3. redux-saga๋ž€?

    redux-saga๋Š” React/Redux ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ side-effect(๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ ๊ฐ™์€ ๋น„๋™๊ธฐ์‹ ๋ฐ ๋ธŒ๋ผ์šฐ์ € ์บ์‹œ ์ ‘๊ทผ๊ณผ ๊ฐ™์ด ๋ถˆ์พŒํ•œ ๊ฒƒ)๋ฅผ ๋”์šฑ ์‰ฝ๊ณ  ํšจ๊ณผ์ ์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฒƒ์„ ๋ชฉํ‘œ๋กœ ํ•˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๋‹ค.

    NPM์—์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค.

    $ npm install --save redux-saga
  4. redux-saga์˜ ์ •์‹  ๋ชจ๋ธ์€?

    Saga ๋Š” ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์—์„œ ๋ณ„๋„์˜ thread์™€ ์œ ์‚ฌํ•˜๋ฉฐ, side-effect ์˜ ์ฃผ๋œ ์›์ธ์ด๋‹ค. redux-saga ๋Š” redux middleware๋กœ, ์ด thread๋Š” ์ผ๋ฐ˜์ ์ธ Redux action์œผ๋กœ ๋ฉ”์ธ ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์—์„œ ์‹œ์ž‘, ์ผ์‹œ ์ค‘์ง€ ๋ฐ ์ทจ์†Œ ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์ „์ฒด Redux ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ state์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, Redux action๋„ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋‹ค.

  5. redux-saga์—์„œ call()๊ณผ put()์˜ ์ฐจ์ด์ ์€?

    call()๊ณผ put() ๋‘˜ ๋‹ค effect ์ƒ์„ฑํ•จ์ˆ˜์ด๋‹ค. call() ํ•จ์ˆ˜๋Š” effect ์„ค๋ช…์„ ์ž‘์„ฑํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋ฉฐ ๋ฏธ๋“ค์›จ์–ด๊ฐ€ promise๋ฅผ ํ˜ธ์ถœํ•˜๋„๋ก ํ•œ๋‹ค. put() ํ•จ์ˆ˜๋Š” effect๋ฅผ ์ž‘์„ฑํ•˜์—ฌ ๋ฏธ๋“ค์›จ์–ด๊ฐ€ action์„ store์— ์ „๋‹ฌํ•˜๋„๋ก ํ•ด์ค€๋‹ค.

    ํŠน์ • ์‚ฌ์šฉ์ž ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š”๋ฐ effect๊ฐ€ ์–ด๋–ป๊ฒŒ ์ž‘๋™ํ•˜๋Š”์ง€ ์˜ˆ๋ฅผ ๋“ค์–ด๋ณด์ž.

    function* fetchUserSaga(action) {
      // `call` function accepts rest arguments, which will be passed to `api.fetchUser` function.
      // Instructing middleware to call promise, it resolved value will be assigned to `userData` variable
      const userData = yield call(api.fetchUser, action.userId)
    
      // Instructing middleware to dispatch corresponding action.
      yield put({
        type: 'FETCH_USER_SUCCESS',
        userData
      })
    }
  6. Redux Thunk๋ž€?

    Redux Thunk ๋ฏธ๋“ค์›จ์–ด๋Š” action ๋Œ€์‹  ํ•จ์ˆ˜๋ฅผ ๋ฆฌํ„ดํ•˜๋Š” action ์ƒ์„ฑ์ž๋ฅผ ์ž‘์„ฑํ•˜๋„๋ก ํ•ด์ค€๋‹ค. thunk๋Š” action์˜ dispatch๋ฅผ ์ง€์—ฐ์‹œํ‚ค๊ฑฐ๋‚˜ ํŠน์ •ํ•œ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•œ ๊ฒฝ์šฐ dispatch ํ•ด์•ผ ํ•˜๋Š” ๊ณณ์— ์‚ฌ์šฉ๋œ๋‹ค. ๋‚ด๋ถ€ ํ•จ์ˆ˜๋Š” store ๋ฉ”์„œ๋“œ dispatch()์™€ getState()๋ฅผ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋ฐ›๋Š”๋‹ค.

  7. redux-saga์™€ redux-thunk์˜ ์ฐจ์ด์ ์€?

    Redux Thunk์™€ Redux Saga๋Š” side effects๋ฅผ ์ฒ˜๋ฆฌํ•œ๋‹ค. ๋Œ€๋ถ€๋ถ„์˜ ์‹œ๋‚˜๋ฆฌ์˜ค์—์„œ Thunk๋Š” Promises๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ฒ˜๋ฆฌํ•˜๊ณ  Saga๋Š” Generators๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. Thunk๋Š” ์‚ฌ์šฉํ•˜๊ธฐ ์‰ฝ๊ณ  Promises๋Š” ๋งŽ์€ ๊ฐœ๋ฐœ์ž์—๊ฒŒ ์นœ์ˆ™ํ•˜๋‹ค. Sagas/Generators๋Š” ๋” ๊ฐ•๋ ฅํ•˜์ง€๋งŒ, ํ•™์Šต์„ ํ•  ํ•„์š”๊ฐ€ ์žˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ๋‘ ๋ฏธ๋“ค์›จ์–ด๋Š” ๊ณต์กดํ•  ์ˆ˜ ์žˆ์–ด์„œ ํ•„์š”ํ•  ๋•Œ Thunks๋กœ ์‹œ์ž‘ํ•˜๊ณ  ํ•„์š”ํ•  ๋•Œ Sagas๋ฅผ ์†Œ๊ฐœํ•  ์ˆ˜ ์žˆ๋‹ค.

  8. Redux DevTools์ด๋ž€?

    Redux DevTools๋Š” ํ•ซ ๋ฆฌ๋กœ๋”ฉ, action ๋ฆฌํ”Œ๋ ˆ์ด ๋ฐ ์‚ฌ์šฉ์ž ์ •์˜ UI ๊ฐ€๋Šฅํ•œ UI๊ฐ€ ์žˆ๋Š” Redux์˜ ์‹ค์‹œ๊ฐ„ ํŽธ์ง‘ํ•˜๋Š” ์‹œ๊ฐ„ ์—ฌํ–‰ ํ™˜๊ฒฝ์ด๋‹ค. Redux DevTools ์„ค์น˜ ์™€ ํ”„๋กœ์ ํŠธ ํ†ตํ•ฉ์„ ๋ฐฉํ•ดํ•˜์ง€ ์•Š์œผ๋ ค๋ฉด, Chrome ๋ฐ Firefox ์šฉ Redux DevTools Extension ์‚ฌ์šฉ์„ ๊ณ ๋ คํ•ด์•ผ ํ•œ๋‹ค.

  9. Redux DevTools์˜ ๊ธฐ๋Šฅ์—๋Š” ๋ฌด์—‡์ด ์žˆ๋‚˜?

    1. ๋ชจ๋“  state์™€ action payload๋ฅผ ๊ฒ€์‚ฌํ•  ์ˆ˜ ์žˆ๋‹ค.
    2. action์„ ์ทจ์†Œํ•˜์—ฌ ์‹œ๊ฐ„์„ ๋˜๋Œ๋ฆด ์ˆ˜ ์žˆ๋‹ค.
    3. reducer ์ฝ”๋“œ๋ฅผ ๋ณ€๊ฒฝํ•˜๋ฉด, ๊ฐ ๋‹จ๊ณ„๋ณ„ action์ด ๋‹ค์‹œ ํ‰๊ฐ€๋œ๋‹ค.
    4. reducers๊ฐ€ throw๋˜๋ฉด, ์–ด๋–ค action์ด ๋ฐœ์ƒํ–ˆ๋Š”์ง€์™€ ์˜ค๋ฅ˜๊ฐ€ ๋ฌด์—‡์ธ์ง€ ์•Œ ์ˆ˜ ์žˆ๋‹ค.
    5. persistState() store enhancer๋ฅผ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜๋ฉด, ํŽ˜์ด์ง€๋ฅผ ๋‹ค์‹œ ๋กœ๋“œํ•ด๋„ ๋””๋ฒ„๊ทธ ์„ธ์…˜์„ ์œ ์ง€ํ•  ์ˆ˜ ์žˆ๋‹ค.
  10. Redux selectors๊ฐ€ ๋ฌด์—‡์ด๋ฉฐ ์‚ฌ์šฉํ•ด์•ผํ•˜๋Š” ์ด์œ ๋Š”?

    Selectors๋Š” Redux state๋ฅผ ์ธ์ˆ˜๋กœ ์‚ฌ์šฉํ•˜๋ฉฐ ์ผ๋ถ€ ๋ฐ์ดํ„ฐ๋ฅผ component์— ์ „๋‹ฌํ•˜๋Š” ํ•จ์ˆ˜์ด๋‹ค.

    ์˜ˆ๋ฅผ ๋“ค์–ด, state์—์„œ ์‚ฌ์šฉ์ž ์„ธ๋ถ€ ์‚ฌํ•ญ์„ ์–ป์œผ๋ ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ํ•˜๋ฉด ๋œ๋‹ค.

    const getUserData = state => state.user.data
  11. Redux Form์ด๋ž€?

    Redux Form์€ React ๋ฐ Redux์™€ ํ•จ๊ป˜ ์ž‘๋™ํ•˜๋ฉฐ React์˜ ์–‘์‹์—์„œ Redux๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ๋“  state๋ฅผ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋‹ค. Redux Form์€ ์›์‹œ HTML5 ์ž…๋ ฅ๊ณผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, Material UI, React Widgets ๋ฐ React Bootstrap๊ณผ ๊ฐ™์€ ์ผ๋ฐ˜์ ์ธ UI ํ”„๋ ˆ์ž„์›Œํฌ์™€๋„ ์ž˜ ์ž‘๋™ํ•œ๋‹ค.

  12. Redux Form์˜ ์ฃผ์š” ๊ธฐ๋Šฅ์€?

    1. Redux store๋ฅผ ํ†ตํ•œ ํ•„๋“œ ๊ฐ’ ์ง€์†.
    2. ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ (sync/async) ๋ฐ ์ œ์ถœ.
    3. ํ•„๋“œ ๊ฐ’์˜ ํ˜•์‹ํ™”, parsing ๋ฐ ํ‘œ์ค€ํ™”.
  13. Redux์— ์—ฌ๋Ÿฌ ๋ฏธ๋“ค์›จ์–ด๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    applyMiddleware()๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

    ์˜ˆ๋ฅผ ๋“ค์–ด, redux-thunk์™€ logger๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ applyMiddleware()์— ์ธ์ˆ˜๋กœ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋‹ค.

    import { createStore, applyMiddleware } from 'redux'
    const createStoreWithMiddleware = applyMiddleware(ReduxThunk, logger)(createStore)
  14. Redux์—์„œ ์ดˆ๊ธฐ state๋ฅผ ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    createStore์— ๋‘๋ฒˆ์งธ ์ธ์ž๋กœ ์ดˆ๊ธฐ state๋ฅผ ์ „๋‹ฌํ•ด์•ผํ•œ๋‹ค.

    const rootReducer = combineReducers({
      todos: todos,
      visibilityFilter: visibilityFilter
    })
    
    const initialState = {
      todos: [{ id: 123, name: 'example', completed: false }]
    }
    
    const store = createStore(
      rootReducer,
      initialState
    )
  15. Relay์™€ Redux์˜ ์ฐจ์ด์ ์€?

    Relay์™€ Redux๋Š” ๋‘˜ ๋‹ค ๋‹จ์ผ ์ €์žฅ์†Œ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋Š” ์ ์—์„œ ์œ ์‚ฌํ•˜๋‹ค. ๊ฐ€์žฅ ํฐ ์ฐจ์ด์ ์€ relay๋Š” ์„œ๋ฒ„์—์„œ ์‹œ์ž‘๋œ state๋งŒ ๊ด€๋ฆฌํ•˜๊ณ  ์ƒํƒœ์— ๋Œ€ํ•œ ๋ชจ๋“  ์ ‘๊ทผ์„ GraphQL queries(๋ฐ์ดํ„ฐ ์ฝ๊ธฐ) ๋ฐ mutations(๋ฐ์ดํ„ฐ ๋ณ€๊ฒฝ)๋ฅผ ํ†ตํ•ด์„œ ํ•œ๋‹ค. Relay๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์บ์‹œํ•˜๊ณ  ๋ณ€๊ฒฝ๋œ ๋ฐ์ดํ„ฐ๋งŒ ๊ฐ€์ ธ์˜ค๊ณ  ๋” ์ด์ƒ ๊ฐ€์ ธ์˜ค์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ๋ฅผ ์ตœ์ ํ™”ํ•  ์ˆ˜ ์žˆ๋‹ค.

React Native

  1. What is the difference between React Native and React?

    React is a JavaScript library, supporting both front end web and being run on the server, for building user interfaces and web applications.

    React Native is a mobile framework that compiles to native app components, allowing you to build native mobile applications (iOS, Android, and Windows) in JavaScript that allows you to use React to build your components, and implements React under the hood.

  2. How to test React Native apps?

    React Native can be tested only in mobile simulators like iOS and Android. You can run the app in your mobile using expo app (https://expo.io) Where it syncs using QR code, your mobile and computer should be in same wireless network.

  3. How to do logging in React Native?

    You can use console.log, console.warn, etc. As of React Native v0.29 you can simply run the following to see logs in the console:

    $ react-native log-ios
    $ react-native log-android
    
  4. How to debug your React Native?

    Follow the below steps to debug React Native app:

    1. Run your application in the iOS simulator.
    2. Press Command + D and a webpage should open up at http://localhost:8081/debugger-ui.
    3. Enable Pause On Caught Exceptions for a better debugging experience.
    4. Press Command + Option + I to open the Chrome Developer tools, or open it via View -> Developer -> Developer Tools.
    5. You should now be able to debug as you normally would.

React supported libraries & Integration

  1. reselect์ด๋ž€ ๋ฌด์—‡์ด๋ฉฐ ์–ด๋–ป๊ฒŒ ์ž‘๋™ํ•˜๋‚˜?

    Reselect๋Š” ๋ฉ”๋ชจ์ด์ œ์ด์…˜ ๊ฐœ๋…์„ ์‚ฌ์šฉํ•˜๋Š” selector library (Redux ์šฉ)์ด๋‹ค. ์›๋ž˜ Redux์™€ ๊ฐ™์€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ state์—์„œ ํŒŒ์ƒ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ณ„์‚ฐํ•˜๊ธฐ ์œ„ํ•ด ์ž‘์„ฑ๋˜์—ˆ์ง€๋งŒ, ์•„ํ‚คํ…์ณ๋‚˜ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—๋Š” ์—ฐ๊ฒฐํ•  ์ˆ˜ ์—†๋‹ค.

    Reselect์€ ๋งˆ์ง€๋ง‰ ํ˜ธ์ถœ์˜ ๋งˆ์ง€๋ง‰ ์ž…/์ถœ๋ ฅ ์‚ฌ๋ณธ์„ ์œ ์ง€ํ•˜๊ณ , ์ž…๋ ฅ ์ค‘ ํ•˜๋‚˜๊ฐ€ ๋ณ€๊ฒฝ๋œ ๊ฒฝ์šฐ์—๋งŒ ๊ฒฐ๊ณผ๋ฅผ ๋‹ค์‹œ ๊ณ„์‚ฐํ•œ๋‹ค. ๋™์ผํ•œ ์ž…๋ ฅ์ด ๋™์‹œ์— ๋‘ ๋ฒˆ ์ œ๊ณต๋˜๋ฉด, Reselect๋Š” ์บ์‹œ๋œ ์ถœ๋ ฅ์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ๋ฉ”๋ชจ ๋ฐ ์บ์‹œ๋Š” ์™„์ „ํžˆ ์‚ฌ์šฉ์ž ์ •์˜ํ•  ์ˆ˜ ์žˆ๋‹ค.

  2. Flow๋ž€?

    Flow๋Š” JavaScript์—์„œ ํƒ€์ž… ์˜ค๋ฅ˜๋ฅผ ์žก์•„๋‚ด๊ธฐ ์œ„ํ•ด ์„ค๊ณ„๋œ ์ •์  ํƒ€์ž… ๊ฒ€์‚ฌ๊ธฐ ์ด๋‹ค. Flow ํƒ€์ž…์€ ๊ธฐ์กด ํƒ€์ž… ์‹œ์Šคํ…œ๋ณด๋‹ค ํ›จ์”ฌ ์„ธ๋ฐ€ํ•œ ์ฐจ์ด๋ฅผ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, Flow๋Š” ๋Œ€๋ถ€๋ถ„์˜ ํƒ€์ž… ์‹œ์Šคํ…œ๊ณผ ๋‹ฌ๋ฆฌ null๊ณผ ๊ด€๋ จ๋œ ์˜ค๋ฅ˜๋ฅผ ์ฐพ์•„๋‚ด๋Š” ๋ฐ ๋„์›€์ด ๋œ๋‹ค.

  3. Flow์™€ PropTypes์˜ ์ฐจ์ด์ ์€?

    Flow๋Š” ์–ธ์–ด์˜ ์ƒ์œ„ ์ง‘ํ•ฉ์„ ์‚ฌ์šฉํ•˜๋Š” ์ •์  ๋ถ„์„ ๋„๊ตฌ (์ •์  ๊ฒ€์‚ฌ๊ธฐ)๋กœ, ๋ชจ๋“  ์ฝ”๋“œ์— ํƒ€์ž… ์–ด๋…ธํ…Œ์ด์…˜์„ ์ถ”๊ฐ€ํ•˜์—ฌ ์ปดํŒŒ์ผ ํƒ€์ž„์— ์ „์ฒด ๋ฒ„๊ทธ ํด๋ž˜์Šค๋ฅผ ์žก์„ ์ˆ˜ ์žˆ๋‹ค. PropTypes์€ React์— ํŒจ์น˜๋œ ๊ธฐ๋ณธ ํƒ€์ž… ๊ฒ€์‚ฌ๊ธฐ (๋Ÿฐํƒ€์ž„ ๊ฒ€์‚ฌ๊ธฐ)์ด๋‹ค. ์ฃผ์–ด์ง„ ์ปดํฌ๋„ŒํŠธ์— ์ „๋‹ฌ๋˜๋Š” props ํƒ€์ž… ์ด์™ธ์˜ ๊ฒƒ์€ ํ™•์ธํ•  ์ˆ˜ ์—†๋‹ค. ์ „์ฒด ํ”„๋กœ์ ํŠธ์— ์œ ์—ฐํ•œ ํƒ€์ž…๊ฒ€์‚ฌ๋ฅผ ์›ํ•  ๊ฒฝ์šฐ Flow / TypeScript๊ฐ€ ์ ํ•ฉํ•˜๋‹ค.

  4. React์—์„œ Font Awesome icons๋ฅผ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋‚˜?

    ์•„๋ž˜์˜ ์˜ˆ์ œ๋Š” React์— Font Awesome์„ ํฌํ•จ์‹œํ‚ค๋Š” ๊ฒƒ์ด๋‹ค.

    1. font-awesome ์„ค์น˜ํ•œ๋‹ค.
    $ npm install --save font-awesome
    1. index.js ํŒŒ์ผ์— font-awesome Importํ•œ๋‹ค.
    import 'font-awesome/css/font-awesome.min.css'
    1. className์— Font Awesome ํด๋ž˜์Šค๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.
    render() {
      return <div><i className={'fa fa-spinner'} /></div>
    }
  5. React Dev Tools์ด๋ž€?

    React Developer Tools ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ปดํฌ๋„ŒํŠธ props์™€ state๋ฅผ ํฌํ•จํ•œ ์ปดํฌ๋„ŒํŠธ ๊ณ„์ธต์„ ๊ฒ€์‚ฌํ•  ์ˆ˜ ์žˆ๋‹ค. ๋ธŒ๋ผ์šฐ์ € ํ™•์žฅ (Chrome๊ณผ Firefox ์šฉ), ๋…๋ฆฝ์‹คํ–‰ํ˜• ์•ฑ(Safari, IE, ์™€ React Native ๋“ฑ์˜ ๋‹ค๋ฅธ ํ™˜๊ฒฝ์—์„œ ์ž‘๋™ํ•˜๋Š”)์œผ๋กœ ์žˆ๋‹ค.

    ๋‹ค๋ฅธ ๋ธŒ๋ผ์šฐ์ € ๋˜๋Š” ํ™˜๊ฒฝ์—์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๊ณต์‹ ํ™•์žฅ

    1. Chrome extension
    2. Firefox extension
    3. Standalone app (Safari, React Native, etc)
  6. ๋กœ์ปฌ ํŒŒ์ผ์„ ์—ฐ Chrome์—์„œ DevTools์ด ๋กœ๋”ฉ๋˜์ง€ ์•Š๋Š” ์ด์œ ๋Š”?

    ๋ธŒ๋ผ์šฐ์ €์—์„œ ๋กœ์ปฌ HTML ํŒŒ์ผ(file://...)์„ ์—ฐ ๊ฒฝ์šฐ ๋จผ์ € Chrome Extensions์„ ์—ด๊ณ  Allow access to file URLs์„ ์„ ํƒํ•ด์•ผ ํ•œ๋‹ค.

  7. React์—์„œ Polymer๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    1. Polymer ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ๋งŒ๋“ ๋‹ค.

      <link rel='import' href='../../bower_components/polymer/polymer.html' />
      Polymer({
        is: 'calender-element',
        ready: function() {
          this.textContent = 'I am a calender'
        }
      })
    2. Polymer ์ปดํฌ๋„ŒํŠธ HTML ํƒœ๊ทธ๋ฅผ HTML ๋ฌธ์„œ๋กœ ๊ฐ€์ ธ์™€์„œ ๋งŒ๋“ ๋‹ค. (์˜ˆ : React ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ index.html๋กœ ๊ฐ€์ ธ์˜ค์‹ญ์‹œ์˜ค.)

      <link rel='import' href='./src/polymer-components/calender-element.html'>
      1. JSX ํŒŒ์ผ์—์„œ ํ•ด๋‹น ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
      import React from 'react'
      
      class MyComponent extends React.Component {
        render() {
          return (
            <calender-element />
          )
        }
      }
      
      export default MyComponent
  8. Vue.js๋ณด๋‹ค React์˜ ์žฅ์ ์€ ๋ฌด์—‡์ธ๊ฐ€?

    React๊ฐ€ Vue.js์— ๋น„ํ•ด ์•„๋ž˜์™€ ๊ฐ™์€ ์žฅ์ ์ด ์žˆ๋‹ค.

    1. ๋Œ€๊ทœ๋ชจ ์•ฑ ๊ฐœ๋ฐœ์— ์žˆ์–ด์„œ ๋” ๋งŽ์€ ์œ ์—ฐ์„ฑ์„ ์ œ๊ณตํ•œ๋‹ค.
    2. ํ…Œ์ŠคํŠธํ•˜๊ธฐ ์‰ฝ๋‹ค.
    3. ๋ชจ๋ฐ”์ผ ์•ฑ ์ œ์ž‘์— ์ ํ•ฉํ•˜๋‹ค.
    4. ๋” ๋งŽ์€ ์ •๋ณด์™€ ์œ ์šฉํ•œ ์†”๋ฃจ์…˜์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.
  9. React์™€ Angular์˜ ์ฐจ์ด์ ์€?

    React Angular
    React๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๋ฉฐ View ๋‹จ๋งŒ ์žˆ๋‹ค. Angular๋Š” ํ”„๋ ˆ์ž„์›Œํฌ์ด๋ฉฐ ์™„์ „ํ•œ MVC ๊ธฐ๋Šฅ์ด ์žˆ๋‹ค.
    React๋Š” ์„œ๋ฒ„ ์ธก์—์„œ ๋ Œ๋”๋งํ•  ์ˆ˜ ์žˆ๋‹ค. AngularJS๋Š” ํด๋ผ์ด์–ธํŠธ ์ธก์—์„œ๋งŒ ๋ Œ๋”๋ง ๋˜์ง€๋งŒ Angular 2 ์ด์ƒ์—์„œ ์„œ๋ฒ„ ์ธก์—์„œ ๋ Œ๋”๋ง์ด ๋œ๋‹ค.
    React๋Š” ํ˜ผ๋ž€์Šค๋Ÿฌ์šธ ์ˆ˜ ์žˆ๋Š” JS๋ฅผ HTML์ฒ˜๋Ÿผ ๋ณด์ด๋Š” JSX๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. Angular๋Š” HTML์— ๋Œ€ํ•œ ํ…œํ”Œ๋ฆฟ ์ ‘๊ทผ ๋ฐฉ์‹์„ ๋”ฐ๋ฅด๋ฏ€๋กœ ์ฝ”๋“œ๊ฐ€ ๋” ์งง๊ณ  ์ดํ•ดํ•˜๊ธฐ ์‰ฝ๋‹ค.
    ๋ชจ๋ฐ”์ผ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋นŒ๋“œํ•˜๊ธฐ ์œ„ํ•œ React ์œ ํ˜•์ธ React Native๋Š” ๋” ๋น ๋ฅด๊ณ  ์•ˆ์ •์ ์ด๋‹ค. Ionic, Angular์˜ ๋ชจ๋ฐ”์ผ ๋„ค์ดํ‹ฐ๋ธŒ ์•ฑ์€ ์ƒ๋Œ€์ ์œผ๋กœ ๋œ ์•ˆ์ •์ ์ด๋ฉฐ ๋Š๋ฆฌ๋‹ค.
    React์—์„œ ๋ฐ์ดํ„ฐ๋Š” ํ•œ ๋ฐฉํ–ฅ์œผ๋กœ๋งŒ ํ๋ฅด๋ฏ€๋กœ ๋””๋ฒ„๊น…์ด ์‰ฝ๋‹ค. Angular์—์„œ๋Š” ๋ฐ์ดํ„ฐ๊ฐ€ ์–‘๋ฐฉํ–ฅ์œผ๋กœ ํ๋ฅธ๋‹ค. ์ฆ‰ ์ž์‹๊ณผ ๋ถ€๋ชจ ์‚ฌ์ด์— ์–‘๋ฐฉํ–ฅ ๋ฐ์ดํ„ฐ ๋ฐ”์ธ๋”ฉ์ด ์žˆ์Œ์œผ๋กœ ๋””๋ฒ„๊น…์ด ์–ด๋ ค์šด ๊ฒฝ์šฐ๊ฐ€ ๋งŽ๋‹ค.
  10. DevTools์— React ํƒญ์ด ํ‘œ์‹œ๋˜์ง€ ์•Š๋Š” ์ด์œ ๋Š”?

    ํŽ˜์ด์ง€๊ฐ€ ๋กœ๋”ฉ๋˜๋ฉด, React DevTools๊ฐ€ __REACT_DEVTOOLS_GLOBAL_HOOK__์ด๋ผ๋Š” ์ „์—ญ์„ ์„ค์ •ํ•œ ํ›„ ์ดˆ๊ธฐํ™” ์ค‘์— React๊ฐ€ ํ•ด๋‹น hook๊ณผ ํ†ต์‹ ํ•œ๋‹ค. ์›น์‚ฌ์ดํŠธ๊ฐ€ React๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ฑฐ๋‚˜ React๊ฐ€ DevTool๊ณผ ํ†ต์‹ ํ•˜์ง€ ๋ชปํ•˜๋ฉด ํƒญ์ด ํ‘œ์‹œ๋˜์ง€ ์•Š๋Š”๋‹ค.

  11. Styled Components๋ž€?

    styled-components๋Š” React ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์Šคํƒ€์ผ๋ง์„ ์œ„ํ•œ JavaScript ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๋‹ค. ์Šคํƒ€์ผ๊ณผ ์ปดํฌ๋„ŒํŠธ ๊ฐ„์˜ ๋งคํ•‘์„ ์ œ๊ฑฐํ•˜๊ณ  JavaScript๋กœ ๋ณด๊ฐ•๋œ ์‹ค์ œ CSS๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

  12. Styled Components์˜ ์˜ˆ์‹œ๋Š”?

    ๊ฐ๊ฐ์— ๋Œ€ํ•ด ํŠน์ • ์Šคํƒ€์ผ๋กœ <Title>๊ณผ <Wrapper> ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋งŒ๋“ค์–ด ๋ณด์ž.

    import React from 'react'
    import styled from 'styled-components'
    
    // Create a <Title> component that renders an <h1> which is centered, red and sized at 1.5em
    const Title = styled.h1`
      font-size: 1.5em;
      text-align: center;
      color: palevioletred;
    `
    
    // Create a <Wrapper> component that renders a <section> with some padding and a papayawhip background
    const Wrapper = styled.section`
      padding: 4em;
      background: papayawhip;
    `

    Title๊ณผ Wrapper๋Š” ์ด์ œ ์„œ๋กœ ๋‹ค๋ฅธ react component์ฒ˜๋Ÿผ ๋ Œ๋”๋ง ํ•  ์ˆ˜ ์žˆ๋Š” ์ปดํฌ๋„ŒํŠธ์ด๋‹ค.

    <Wrapper>
      <Title>{'Lets start first styled component!'}</Title>
    </Wrapper>
  13. Relay๋ž€?

    Relay๋Š” React View ๊ณ„์ธต์„ ์‚ฌ์šฉํ•˜์—ฌ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋ฐ์ดํ„ฐ ๊ณ„์ธต๊ณผ ํด๋ผ์ด์–ธํŠธ-์„œ๋ฒ„ ํ†ต์‹ ์„ ์ œ๊ณตํ•˜๊ธฐ ์œ„ํ•œ JavaScript ํ”„๋ ˆ์ž„์›Œํฌ์ด๋‹ค.

  14. create-react-app ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ TypeScript๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•?

    [email protected] ์ด์ƒ๋ถ€ํ„ฐ, typescript๋ฅผ ๊ธฐ๋ณธ์ ์œผ๋กœ ์ง€์›ํ•œ๋‹ค. ์•„๋ž˜์™€ ๊ฐ™์ด --typescript ์˜ต์…˜์„ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋‹ค.

    npx create-react-app my-app --typescript
    
    # or
    
    yarn create react-app my-app --typescript

    ๊ทธ๋Ÿฌ๋‚˜ ๋” ๋‚ฎ์€ ๋ฒ„์ „์˜ react scripts์˜ ๊ฒฝ์šฐ ์ƒˆ ํ”„๋กœ์ ํŠธ๋ฅผ ๋งŒ๋“œ๋Š” ๋™์•ˆ --scripts-version ์˜ต์…˜์„ react-scripts-ts๋กœ ์ œ๊ณตํ•˜์—ฌ๋ผ. react-scripts-ts๋Š” ํ‘œ์ค€ create-react-app ํ”„๋กœ์ ํŠธ ํŒŒ์ดํ”„๋ผ์ธ์„ ์ทจํ•˜๊ณ  TypeScript๋ฅผ ๋ฏน์Šค๋กœ ๊ฐ€์ ธ์˜ค๊ธฐ ์œ„ํ•œ ์กฐ์ • ์„ธํŠธ์ด๋‹ค.

    ์ด์ œ ํ”„๋กœ์ ํŠธ ๋ ˆ์ด์•„์›ƒ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์•„์•ผ ํ•œ๋‹ค.

    my-app/
    โ”œโ”€ .gitignore
    โ”œโ”€ images.d.ts
    โ”œโ”€ node_modules/
    โ”œโ”€ public/
    โ”œโ”€ src/
    โ”‚  โ””โ”€ ...
    โ”œโ”€ package.json
    โ”œโ”€ tsconfig.json
    โ”œโ”€ tsconfig.prod.json
    โ”œโ”€ tsconfig.test.json
    โ””โ”€ tslint.json
    

Miscellaneous

  1. Reselect ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ์ฃผ์š” ๊ธฐ๋Šฅ์€?

    1. Selectors๋Š” ํŒŒ์ƒ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ณ„์‚ฐํ•˜์—ฌ, Redux๊ฐ€ ๊ฐ€๋Šฅํ•œ ์ตœ์†Œ์˜ state๋ฅผ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•œ๋‹ค.
    2. Selectors๋Š” ํšจ์œจ์ ์ด๋‹ค. selector๋Š” ์ธ์ž ์ค‘ ํ•˜๋‚˜๋„ ๋ณ€ํ™”๊ฐ€ ์—†๋‹ค๋ฉด ์žฌ๊ณ„์‚ฐ์„ ํ•˜์ง€ ์•Š๋Š”๋‹ค.
    3. Selectors๋Š” composableํ•˜๋‹ค. ๋‹ค๋ฅธ selector์— ๋Œ€ํ•œ ์ž…๋ ฅ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
  2. Reselect ์‚ฌ์šฉ๋ฒ•์— ๋Œ€ํ•œ ์˜ˆ์‹œ๋Š”?

    Reselect์˜ ๊ฐ„๋‹จํ•œ ์‚ฌ์šฉ๋ฒ•์œผ๋กœ๋Š” ๋‹ค๋ฅธ ์ˆ˜๋Ÿ‰์˜ ์„ ์  ์ฃผ๋ฌธ์„ ๊ณ„์‚ฐํ•ด๋ณด์ž.

    import { createSelector } from 'reselect'
    
    const shopItemsSelector = state => state.shop.items
    const taxPercentSelector = state => state.shop.taxPercent
    
    const subtotalSelector = createSelector(
      shopItemsSelector,
      items => items.reduce((acc, item) => acc + item.value, 0)
    )
    
    const taxSelector = createSelector(
      subtotalSelector,
      taxPercentSelector,
      (subtotal, taxPercent) => subtotal * (taxPercent / 100)
    )
    
    export const totalSelector = createSelector(
      subtotalSelector,
      taxSelector,
      (subtotal, tax) => ({ total: subtotal + tax })
    )
    
    let exampleState = {
      shop: {
        taxPercent: 8,
        items: [
          { name: 'apple', value: 1.20 },
          { name: 'orange', value: 0.95 },
        ]
      }
    }
    
    console.log(subtotalSelector(exampleState)) // 2.15
    console.log(taxSelector(exampleState))      // 0.172
    console.log(totalSelector(exampleState))    // { total: 2.322 }
  3. Redux์—์„œ action์ด๋ž€?

    Actions์€ ์‘์šฉํ”„๋กœ๊ทธ๋žจ์—์„œ store๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด๋‚ด๋Š” ์ผ๋ฐ˜ JavaScript ๊ฐ์ฒด๋‚˜ ์ •๋ณด์˜ payload์ด๋‹ค. ์ด๊ฒƒ๋“ค์€ store์— ๋Œ€ํ•œ ์œ ์ผํ•œ ์ •๋ณด ์†Œ์Šค์ด๋‹ค. Actions์—๋Š” ์ˆ˜ํ–‰ ์ค‘์ธ action ์œ ํ˜•์„ ๋‚˜ํƒ€๋‚ด๋Š” type ์†์„ฑ์ด ์žˆ์–ด์•ผ ํ•œ๋‹ค.

    ์ƒˆ๋กœ์šด ํ•  ์ผ ํ•ญ๋ชฉ ์ถ”๊ฐ€๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๋™์ž‘์— ๋Œ€ํ•œ ์˜ˆ์‹œ์ด๋‹ค.

    {
      type: ADD_TODO,
      text: 'Add todo item'
    }
    
  4. React์˜ ES6 ํด๋ž˜์Šค๋Š” static object์™€ ํ•จ๊ป˜ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ๊ฐ€?

    ์•ˆ๋œ๋‹ค, statics์€ React.createClass()์—์„œ๋งŒ ์ž‘๋™ํ•œ๋‹ค.

    someComponent= React.createClass({
      statics: {
        someMethod: function() {
          // ..
        }
      }
    })

    ๊ทธ๋Ÿฌ๋‚˜ ES6+ classes ์•ˆ์—์„œ static์„ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ ์•„๋ž˜์™€ ๊ฐ™์ด ํด๋ž˜์Šค ์™ธ๋ถ€์—์„œ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

    class Component extends React.Component {
      static propTypes = {
        // ...
      }
    
      static someMethod() {
        // ...
      }
    }
    class Component extends React.Component {
       ....
    }
    
    Component.propTypes = {...}
    Component.someMethod = function(){....}
  5. Redux๋Š” React์—์„œ๋งŒ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ๊ฐ€?

    Redux๋Š” ๋ชจ๋“  UI ๊ณ„์ธต์˜ ๋ฐ์ดํ„ฐ ์ €์žฅ์†Œ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ์ฃผ ์‚ฌ์šฉ์ฒ˜๋Š” React์™€ React Native์ด์ง€๋งŒ, Angular, Angular 2, Vue, Mithril ๋“ฑ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. Redux๋Š” ๋‹ค๋ฅธ ์ฝ”๋“œ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” subscription ๋ฉ”์ปค๋‹ˆ์ฆ˜์„ ์ œ๊ณตํ•œ๋‹ค.

  6. Redux๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ํŠน๋ณ„ํ•œ ๋นŒ๋“œ ๋„๊ตฌ๊ฐ€ ํ•„์š”ํ•œ๊ฐ€?

    Redux๋Š” ES6๋กœ ์ž‘์„ฑ๋˜์—ˆ์œผ๋ฉฐ Webpack๊ณผ Babel์„ ์‚ฌ์šฉํ•˜์—ฌ ES5๋กœ ๋ณ€ํ™˜๋˜์–ด์žˆ๋‹ค. JavaScript ๋นŒ๋“œ ํ”„๋กœ์„ธ์Šค์— ๊ด€๋ จ ์—†์ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•œ๋‹ค. ๋˜ํ•œ Redux๋Š” ๋นŒ๋“œ ํ”„๋กœ์„ธ์Šค ์—†์ด ์ง์ ‘ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” UMD ๋นŒ๋“œ๋ฅผ ์ œ๊ณตํ•œ๋‹ค.

  7. Redux Form initialValues๋Š” state์—์„œ ์–ด๋–ป๊ฒŒ ์—…๋ฐ์ดํŠธํ•˜๋‚˜?

    enableReinitialize : true ์„ค์ •์„ ์ถ”๊ฐ€ํ•ด์•ผ ํ•œ๋‹ค.

    const InitializeFromStateForm = reduxForm({
      form: 'initializeFromState',
      enableReinitialize : true
    })(UserEdit)

    initialValues prop๊ฐ€ ์—…๋ฐ์ดํŠธ๋˜๋ฉด, form๋„ ์—…๋ฐ์ดํŠธ๋œ๋‹ค.

  8. React PropTypes์ด ํ•˜๋‚˜์˜ prop์—์„œ ๋‹ค๋ฅธ ํƒ€์ž…๋“ค์„ ํ—ˆ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    PropTypes์˜ oneOfType() ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

    ์˜ˆ๋ฅผ ๋“ค์–ด, height ์†์„ฑ์€ ์•„๋ž˜์™€ ๊ฐ™์ด string ๋˜๋Š” number ํƒ€์ž…์œผ๋กœ ์ •์˜๋  ์ˆ˜ ์žˆ๋‹ค.

    Component.PropTypes = {
      size: PropTypes.oneOfType([
        PropTypes.string,
        PropTypes.number
      ])
    }
  9. SVG file์„ react ์ปดํฌ๋„ŒํŠธ๋กœ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๋‚˜?

    SVG๋ฅผ ํŒŒ์ผ๋กœ ๋กœ๋“œํ•˜๋Š” ๋Œ€์‹ ์— ์ปดํฌ๋„ŒํŠธ๋กœ ์ง์ ‘ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๋‹ค. ํ•ด๋‹น ๊ธฐ๋Šฅ์€ [email protected] ๋˜๋Š” ๊ทธ ์ด์ƒ์—์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค.

    import { ReactComponent as Logo } from './logo.svg'
    
    const App = () => (
      <div>
        {/* Logo is an actual react component */}
        <Logo />
      </div>
    )

    Note: import์—์„œ ์ค‘๊ด„ํ˜ธ๋ฅผ ์žŠ์–ด์„œ๋Š” ์•ˆ๋œ๋‹ค.

  10. ์ธ๋ผ์ธ ref ์ฝœ๋ฐฑ ๋˜๋Š” ํ•จ์ˆ˜๋ฅผ ๊ถŒ์žฅํ•˜์ง€ ์•Š๋Š” ์ด์œ ๋Š”?

    ref ์ฝœ๋ฐฑ์ด ์ธ๋ผ์ธ ํ•จ์ˆ˜๋กœ ์ •์˜๋œ ๊ฒฝ์šฐ ์—…๋ฐ์ดํŠธ ์ค‘์— ๋‘ ๋ฒˆ ํ˜ธ์ถœ๋œ๋‹ค. (๋จผ์ € null๋กœ, DOM ์š”์†Œ๋กœ ๋‹ค์‹œ ํ˜ธ์ถœ๋จ) ๋ Œ๋”๋ง๋งˆ๋‹ค ํ•จ์ˆ˜์˜ ์ƒˆ ์ธ์Šคํ„ด์Šค๊ฐ€ ์ƒ์„ฑ๋˜๋ฏ€๋กœ React๋Š” ์ด์ „ ์ฐธ์กฐ๋ฅผ ์ง€์šฐ๊ณ  ์ƒˆ ์ฐธ์กฐ๋ฅผ ์„ค์ •ํ•ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

    class UserForm extends Component {
      handleSubmit = () => {
        console.log("Input Value is: ", this.input.value)
      }
    
    
      render () {
       return (
         <form onSubmit={this.handleSubmit}>
           <input
             type='text'
             ref={(input) => this.input = input} /> // Access DOM input in handle submit
           <button type='submit'>Submit</button>
         </form>
       )
     }
    }
๊ทธ๋Ÿฌ๋‚˜ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋งˆ์šดํŠธ๋  ๋•Œ ref ์ฝœ๋ฐฑ์ด ํ•œ ๋ฒˆ ํ˜ธ์ถœ๋˜๊ธฐ๋ฅผ ๊ธฐ๋Œ€ํ•œ๋‹ค. ๋น ๋ฅธ ์ˆ˜์ •์€ ES7 ํด๋ž˜์Šค ๊ตฌ๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ ํ•จ์ˆ˜๋ฅผ ์ •์˜ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

 ```jsx
 class UserForm extends Component {
  handleSubmit = () => {
    console.log("Input Value is: ", this.input.value)
  }

  setSearchInput = (input) => {
    this.input = input
  }

  render () {
    return (
      <form onSubmit={this.handleSubmit}>
        <input
          type='text'
          ref={this.setSearchInput} /> // Access DOM input in handle submit
        <button type='submit'>Submit</button>
      </form>
    )
  }
 }
 ```
  1. react์—์„œ render hijacking์ด๋ž€?

    render hijacking์˜ ๊ฐœ๋…์€ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋‹ค๋ฅธ ์ปดํฌ๋„ŒํŠธ์—์„œ ์ถœ๋ ฅํ•  ๋‚ด์šฉ์„ ์ œ์–ดํ•˜๋Š” ๊ธฐ๋Šฅ์ด๋‹ค. ์‹ค์ œ๋กœ ์ปดํฌ๋„ŒํŠธ๋ฅผ Higher-Order component๋กœ ๊ฐ์‹ธ์„œ ๋‚˜ํƒ€๋‚ธ๋‹ค. ๊ฐ์‹ธ๊ฒŒ ๋˜๋ฉด ์ถ”๊ฐ€ props ์ฃผ์ž…ํ•˜๊ฑฐ๋‚˜ ๋‹ค๋ฅธ ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ์ˆ˜ํ–‰ํ•˜์—ฌ ๋ Œ๋”๋ง ๋…ผ๋ฆฌ๊ฐ€ ๋ณ€๊ฒฝ๋  ์ˆ˜ ์žˆ๋‹ค. ์‹ค์ œ๋กœ hijacking์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š์ง€๋งŒ HOC๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋‹ค๋ฅธ ๋ฐฉ์‹์œผ๋กœ ๋™์ž‘ํ•˜๊ฒŒ ๋œ๋‹ค.

  2. HOC ํŒฉํ† ๋ฆฌ ๊ตฌํ˜„์ด๋ž€?

    React์—์„œ HOC์„ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ํฌ๊ฒŒ 2๊ฐ€์ง€์ด๋‹ค. 1. Props Proxy (PP)์™€ 2. Inheritance Inversion (II). WrappedComponent๋ฅผ ์กฐ์ž‘ํ•˜๊ธฐ ์œ„ํ•œ ๋‹ค์–‘ํ•œ ์ ‘๊ทผ๋ฒ•์ด ์žˆ๋‹ค.

    Props Proxy

    ์ด ์ ‘๊ทผ๋ฒ•์—์„œ HOC render ๋ฉ”์„œ๋“œ๋Š” WrappedComponent ํƒ€์ž…์˜ React Element๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ์šฐ๋ฆฌ๋Š” HOC๊ฐ€ ๋ฐ›์€ props๋ฅผ ์ „๋‹ฌํ•˜๋ฏ€๋กœ, Props Proxy๋ผ๊ณ  ๋ถˆ๋ฆฐ๋‹ค.

    function ppHOC(WrappedComponent) {
     return class PP extends React.Component {
       render() {
         return <WrappedComponent {...this.props}/>
       }
     }
    }

    Inheritance Inversion

    ์ด ์ ‘๊ทผ๋ฒ•์—์„œ ๋ฐ˜ํ™˜๋œ HOC ํด๋ž˜์Šค(Enhancer)๊ฐ€ WrappedComponent๋ฅผ ํ™•์žฅํ•œ๋‹ค. ์ผ๋ถ€ Enhancer ํด๋ž˜์Šค๋ฅผ ํ™•์žฅํ•˜๋Š” WrappedComponent ๋Œ€์‹  Enhancer์— ์˜ํ•ด ์ˆ˜๋™์œผ๋กœ ํ™•์žฅ๋˜๋ฏ€๋กœ Inheritance Inversion์ด๋ผ๊ณ  ๋ถˆ๋ฆฐ๋‹ค. ์ด๋Ÿฌํ•œ ๋ฐฉ์‹์„ ํ†ตํ•ด ๊ทธ๋“ค ์‚ฌ์ด์˜ ๊ด€๊ณ„๋Š” inverseํ•ด์ง„๋‹ค.

    function iiHOC(WrappedComponent) {
     return class Enhancer extends WrappedComponent {
       render() {
         return super.render()
       }
     }
    }
  3. React ์ปดํฌ๋„ŒํŠธ์— ์ˆซ์ž๋ฅผ ์ „๋‹ฌํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    ์ค‘๊ด„ํ˜ธ({})๋ฅผ ํ†ตํ•ด์„œ ์ˆซ์ž๋ฅผ ์ „๋‹ฌํ•ด์•ผ ํ•œ๋‹ค. ์—ฌ๊ธฐ์„œ ๋ฌธ์ž์—ด์€ ๋”ฐ์˜ดํ‘œ๋กœ ๋ฌถ๋Š”๋‹ค.

       React.render(<User age={30} department={"IT"} />, document.getElementById('container'));
  4. ๋ชจ๋“  state๋ฅผ Redux์—์„œ ๊ด€๋ฆฌ๋ฅผ ํ•ด์•ผ ํ•˜๋‚˜? react ๋‚ด๋ถ€ state๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋‚˜?

    ๊ฐœ๋ฐœ์ž์˜ ๊ฒฐ์ •์— ๋‹ฌ๋ ค์žˆ๋‹ค. ์ฆ‰ ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์„ ๊ตฌ์„ฑํ•˜๋Š” state์˜ ์ข…๋ฅ˜์™€ ๊ฐ state์˜ ์œ„์น˜๋ฅผ ๊ฒฐ์ •ํ•˜๋Š” ๊ฒƒ์€ ๊ฐœ๋ฐœ์ž์˜ ์ž‘์—…์ด๋‹ค. ์ผ๋ถ€ ์‚ฌ์šฉ์ž๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ง๋ ฌํ™” ๋ฐ ์ œ์–ด ๊ฐ€๋Šฅํ•œ ๋ฒ„์ „์„ ์œ ์ง€ํ•˜๊ธฐ ์œ„ํ•ด Redux๋กœ ๋ชจ๋“  ๋‹จ์ผ ๋ฐ์ดํ„ฐ๋ฅผ ์œ ์ง€ํ•˜๋Š” ๊ฒƒ์„ ์„ ํ˜ธํ•œ๋‹ค. ๋‹ค๋ฅธ ์‚ฌ๋žŒ๋“ค์€ ์ปดํฌ๋„ŒํŠธ์˜ ๋‚ด๋ถ€ state๋ฅผ โ€œ์ด ๋“œ๋กญ๋‹ค์šด์ด ํ˜„์žฌ ์—ด๋ ค์žˆ์Šต๋‹ˆ๊นŒโ€์™€ ๊ฐ™์ด ์ค‘์š”ํ•˜์ง€ ์•Š๊ฑฐ๋‚˜ UI state๋ฅผ ์œ ์ง€ํ•˜๋Š” ๊ฒƒ์„ ์„ ํ˜ธํ•œ๋‹ค.

    ์•„๋ž˜๋Š” ์–ด๋–ค ์ข…๋ฅ˜์˜ ๋ฐ์ดํ„ฐ๋ฅผ Redux์— ๋„ฃ์–ด์•ผ ํ•˜๋Š”์ง€ ๊ฒฐ์ •ํ•˜๋Š” ๊ทœ์น™์ด๋‹ค.

    1. ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์˜ ๋‹ค๋ฅธ ๋ถ€๋ถ„์ด ๋ฐ์ดํ„ฐ๋ฅผ ๊ด€๋ฆฌํ•˜๋‚˜?
    2. ์›๋ณธ ๋ฐ์ดํ„ฐ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์ถ”๊ฐ€ ํŒŒ์ƒ ๋ฐ์ดํ„ฐ๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•˜๋‚˜?
    3. ์—ฌ๋Ÿฌ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ตฌ๋™ํ•˜๋Š”๋ฐ ๋™์ผํ•œ ๋ฐ์ดํ„ฐ๊ฐ€ ์‚ฌ์šฉ๋˜๋‚˜?
    4. ์ด state๋ฅผ ์ฃผ์–ด์ง„ ์‹œ์  (์ฆ‰, ์‹œ๊ฐ„์—ฌํ–‰ ๋””๋ฒ„๊น…)์œผ๋กœ ๋ณต์›ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ€์น˜๊ฐ€ ์žˆ๋‚˜?
    5. ๋ฐ์ดํ„ฐ๋ฅผ ์บ์‹œ ํ•˜๊ณ  ์‹ถ์€๊ฐ€(์˜ˆ : ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ค์‹œ ์š”์ฒญํ•˜๋Š” ๋Œ€์‹  state๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ ์‚ฌ์šฉํ•˜๋‚˜)?
  5. React์—์„œ registerServiceWorker์˜ ๋ชฉ์ ์€?

    React๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ณ„๋‹ค๋ฅธ ๊ตฌ์„ฑ์—†์ด service worker๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค. service worker๋Š” ์ž์‚ฐ ๋ฐ ๊ธฐํƒ€ ํŒŒ์ผ์„ ์บ์‹ฑํ•˜์—ฌ ์‚ฌ์šฉ์ž๊ฐ€ ์˜คํ”„๋ผ์ธ ์ƒํƒœ์ด๊ฑฐ๋‚˜ ๋„คํŠธ์›Œํฌ ์†๋„๊ฐ€ ๋Š๋ฆฐ ๊ฒฝ์šฐ์—๋„ ํ™”๋ฉด์„ ๋ณผ ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ฃผ๋Š” ์›น API์ด๋‹ค. ์ด๋Š” ๋” ๋‚˜์€ ์‚ฌ์šฉ์ž ๊ฒฝํ—˜์„ ๊ตฌ์ถ•ํ•˜๋Š”๋ฐ ๋„์›€์ด๋œ๋‹ค. ์‚ฌ์ดํŠธ์— ์˜คํ”„๋ผ์ธ ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋‹ค.

       import React from 'react';
       import ReactDOM from 'react-dom';
       import App from './App';
       import registerServiceWorker from './registerServiceWorker';
    
       ReactDOM.render(<App />, document.getElementById('root'));
       registerServiceWorker();
  6. React์˜ memo ํ•จ์ˆ˜๋ž€?

    PureComponent ๋˜๋Š” shouldComponentUpdate ์‚ฌ์šฉ์‹œ ์ž…๋ ฅ props๊ฐ€ ๋™์ผํ•˜๋‹ค๋ฉด, ํด๋ž˜์Šค ์ปดํฌ๋„ŒํŠธ์˜ ๋ Œ๋”๋ง์ด ์ œํ•œ๋  ์ˆ˜ ์žˆ๋‹ค. ์ด์ œ๋Š” ํ•จ์ˆ˜ํ˜• ์ปดํฌ๋„ŒํŠธ๋ฅผ React.memo๋กœ ๊ฐ์‹ธ์„œ ๋™์ผํ•œ ๊ธฐ๋Šฅ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค.

    const MyComponent = React.memo(function MyComponent(props) {
     /* only rerenders if props change */
    });
  7. React์˜ lazy function๋ž€?

    React.lazy ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด dynamic import๋กœ ์ผ๋ฐ˜ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ Œ๋”๋งํ•  ์ˆ˜ ์žˆ๋‹ค. ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ Œ๋”๋ง ๋  ๋•Œ OtherComponent๋ฅผ ํฌํ•จํ•œ ๋ฒˆ๋“ค์„ ์ž๋™์œผ๋กœ ๋กœ๋“œํ•œ๋‹ค. React ์ปดํฌ๋„ŒํŠธ๋ฅผ ํฌํ•จํ•œ ๊ธฐ๋ณธ ๋‚ด๋ณด๋‚ด๊ธฐ๊ฐ€ ์žˆ๋Š” ๋ชจ๋“ˆ๋กœ ํ•ด์„๋˜๋Š” Promise๋ฅผ ๋ฆฌํ„ดํ•ด์•ผํ•œ๋‹ค.

    const OtherComponent = React.lazy(() => import('./OtherComponent'));
    
    function MyComponent() {
     return (
       <div>
         <OtherComponent />
       </div>
     );
    }

    Note: React.lazy ๋ฐ Suspense๋Š” ์•„์ง server-side ๋ Œ๋”๋ง์— ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค. ์„œ๋ฒ„ ๋ Œ๋”๋ง ์•ฑ์—์„œ code-splitting์„ ์ˆ˜ํ–‰ํ•˜๋ ค๋Š” ๊ฒฝ์šฐ ์—ฌ์ „ํžˆ React Loadable์ด ๊ถŒ์žฅ๋œ๋‹ค.

  8. setState๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๋ฐ ์žˆ์–ด ๋ถˆํ•„์š”ํ•œ ์—…๋ฐ์ดํŠธ๋ฅผ ๋ฐฉ์ง€ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    state์˜ ํ˜„์žฌ ๊ฐ’๊ณผ ๊ธฐ์กด์˜ ๊ฐ’์„ ๋น„๊ตํ•˜์—ฌ ๋ฆฌ๋ Œ๋”๋ง์„ ํ• ์ง€ ๋ง์ง€ ๊ฒฐ์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. ๊ฐ’์ด ๊ฐ™๋‹ค๋ฉด null์„ ๋ฐ˜ํ™˜ํ•˜์—ฌ ๋ฆฌ๋ Œ๋”๋ง์„ ๋ฉˆ์ถ”๊ณ  ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ์ตœ์‹ ์˜ state ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์‚ฌ์šฉ์ž ํ”„๋กœํ•„ ์ •๋ณด๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์กฐ๊ฑด๋ถ€๋กœ ๋ Œ๋”๋ง์ด ์ด๋ฃจ์–ด์ง„๋‹ค.

    getUserProfile = user => {
      const latestAddress = user.address;
      this.setState(state => {
        if (state.address === latestAddress) {
          return null;
        } else {
          return { title: latestAddress };
        }
      });
    };
  9. React 16๋ฒ„์ „์—์„œ Array, Strings์™€ Numbers๋ฅผ ๋ Œ๋”๋งํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    Arrays: ์ด์ „ ๋ฆด๋ฆฌ์ฆˆ์™€ ๋‹ค๋ฅด๊ฒŒ, React 16์—์„œ render ๋ฉ”์„œ๋“œ๊ฐ€ ๋‹จ์ผ ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ๋ฐ˜ํ™˜ํ•  ํ•„์š”๋Š” ์—†๋‹ค. ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜ํ•จ์œผ๋กœ์จ ๋ณ„๋„์˜ ๋ฌถ์–ด์ฃผ๋Š” ์—˜๋ฆฌ๋จผํŠธ ์—†์ด ์—ฌ๋Ÿฌ ํ˜•์ œ ์š”์†Œ๋ฅผ ๋ฐ˜ํ™˜ํ•  ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์•„๋ž˜์˜ ๊ฐœ๋ฐœ์ž ๋ชฉ๋ก์„ ๋ณด์ž.

    const ReactJSDevs = () => {
      return [
        <li key="1">John</li>,
        <li key="2">Jackie</li>,
        <li key="3">Jordan</li>
      ];
    }

    ๋ฐฐ์—ด์„ ๋‹ค๋ฅธ ๋ฐฐ์—ด ์ปดํฌ๋„ŒํŠธ์— ๋ณ‘ํ•ฉํ•  ์ˆ˜ ์žˆ๋‹ค.

    const JSDevs = () => {
      return (
        <ul>
          <li>Brad</li>
          <li>Brodge</li>
          <ReactJSDevs/>
          <li>Brandon</li>
        </ul>
      );
    }

    Strings๊ณผ Numbers: render ๋ฉ”์„œ๋“œ์—์„œ ๋ฌธ์ž์—ด๊ณผ ์ˆซ์ž ํƒ€์ž…์„ ๋ฐ˜ํ™˜ํ•  ์ˆ˜ ์žˆ๋‹ค.

    render() {
     return 'Welcome to ReactJS questions';
    }
    // Number
    render() {
     return 2018;
    }
  10. React ํด๋ž˜์Šค์—์„œ ํด๋ž˜์Šค ํ•„๋“œ ์„ ์–ธ ๊ตฌ๋ฌธ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    ํด๋ž˜์Šค ์„ ์–ธ๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ React Class ์ปดํฌ๋„ŒํŠธ๋ฅผ ํ›จ์”ฌ ๊ฐ„๊ฒฐํ•˜๊ฒŒ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค. ์ƒ์„ฑ์ž๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ์ง€์—ญ state๋ฅผ ์ดˆ๊ธฐํ™”ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๋ณ„๋„์˜ ๋ฐ”์ธ๋”ฉ ์—†์ด ํ™”์‚ดํ‘œ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด์„œ ํด๋ž˜์Šค ๋ฉ”์„œ๋“œ๋ฅผ ์„ ์–ธํ•  ์ˆ˜ ์žˆ๋‹ค. ๋ฐ”์ธ๋”ฉ ์—†๋Š” ์ƒ์„ฑ์ž์™€ ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  state์— ๋Œ€ํ•œ ํด๋ž˜์Šค ํ•„๋“œ ์„ ์–ธ์„ ๋ณด์—ฌ์ฃผ๋Š” ์นด์šดํ„ฐ ์˜ˆ์ œ๋ฅผ ๋ณด์ž.

    class Counter extends Component {
      state = { value: 0 };
    
      handleIncrement = () => {
        this.setState(prevState => ({
          value: prevState.value + 1
        }));
      };
    
      handleDecrement = () => {
        this.setState(prevState => ({
          value: prevState.value - 1
        }));
      };
    
      render() {
        return (
          <div>
            {this.state.value}
    
            <button onClick={this.handleIncrement}>+</button>
            <button onClick={this.handleDecrement}>-</button>
          </div>
        )
      }
    }
  11. hooks์ด๋ž€?

    Hooks๋ž€ ํด๋ž˜์Šค๋ฅผ ์ž‘์„ฑํ•˜์ง€ ์•Š๊ณ ๋„ state์™€ ๋‹ค๋ฅธ React ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ์ด๋‹ค. useState hook ์˜ˆ์ œ๋ฅผ ์‚ดํŽด๋ณด์ž.

    import { useState } from 'react';
    
    function Example() {
      // ์ƒˆ๋กœ์šด state ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๋ฉฐ, "count"๋ผ๊ณ  ๋ถˆ๋ฆฐ๋‹ค.
      const [count, setCount] = useState(0);
    
      return (
        <div>
          <p>You clicked {count} times</p>
          <button onClick={() => setCount(count + 1)}>
            Click me
          </button>
        </div>
      );
    }
  12. hooks๋ฅผ ์œ„ํ•ด์„œ ์ง€์ผœ์•ผ ํ•˜๋Š” ๊ทœ์น™์€ ๋ฌด์—‡์ธ๊ฐ€?

    hooks๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ 2๊ฐ€์ง€ ๊ทœ์น™์„ ๋”ฐ๋ผ์•ผํ•œ๋‹ค.

    1. react ํ•จ์ˆ˜์˜ ์ตœ์ƒ์œ„์—์„œ๋งŒ Hooks๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค. ์˜ˆ๋กœ, ๋ฐ˜๋ณต๋ฌธ, ์กฐ๊ฑด๋ฌธ ๋˜๋Š” ์ค‘์ฒฉ ํ•จ์ˆ˜๋‚ด์—์„œ Hooks๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด ์•ˆ ๋œ๋‹ค. ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ Œ๋”๋ง ๋  ๋•Œ๋งˆ๋‹ค Hooks๊ฐ€ ๋™์ผํ•œ ์ˆœ์„œ๋กœ ํ˜ธ์ถœ๋˜๊ณ , ์—ฌ๋Ÿฌ useState ๋ฐ useEffect ํ˜ธ์ถœ๊ฐ„์— Hooks state๊ฐ€ ๋ณด์žฅ๋œ๋‹ค.
    2. Hooks๋Š” React ํ•จ์ˆ˜์—์„œ๋งŒ ํ˜ธ์ถœํ•œ๋‹ค. ์˜ˆ๋กœ, ์ผ๋ฐ˜์ ์ธ JavaScript ํ•จ์ˆ˜์—์„œ Hooks๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด ์•ˆ ๋œ๋‹ค.
  13. hooks๊ฐ€ ํ”„๋กœ์ ํŠธ์˜ ๊ทœ์น™์„ ์ค€์ˆ˜ํ•˜๋„๋ก ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    React ํŒ€์€ ๋‘๊ฐ€์ง€ ๊ทœ์น™์„ ์ ์šฉํ•˜๋Š” eslint-plugin-react-hooks๋ผ๋Š” ESLint ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์ถœ์‹œํ–ˆ๋‹ค. ์•„๋ž˜์˜ ๋ช…๋ น์„ ์‚ฌ์šฉํ•˜์—ฌ ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ํ”„๋กœ์ ํŠธ์— ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋‹ค.

    npm install eslint-plugin-react-hooks@next

    ESLint config ํŒŒ์ผ์— ์•„๋ž˜ ๊ตฌ์„ฑ์„ ์ ์šฉํ•œ๋‹ค.

    // Your ESLint configuration
    {
      "plugins": [
        // ...
        "react-hooks"
      ],
      "rules": {
        // ...
        "react-hooks/rules-of-hooks": "error"
      }
    }

    Note: ์ด ํ”Œ๋Ÿฌ๊ทธ์ธ์€ Create React App์—์„œ ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ ์‚ฌ์šฉํ•˜๋„๋ก ์„ค๊ณ„๋˜์–ด์žˆ๋‹ค.

  14. Flux์™€ Redux์˜ ์ฐจ์ด์ ์€?

    ์•„๋ž˜์— Flux์™€ Redux์˜ ์ฃผ์š”ํ•œ ์ฐจ์ด์ ์ด ์žˆ๋‹ค.

    Flux Redux
    State๋Š” ๋ณ€ํ•œ๋‹ค. State์€ ๋ถˆ๋ณ€ํ•˜๋‹ค.
    Store๋Š” state์™€ ๋ณ€๊ฒฝ๋กœ์ง์„ ํฌํ•จํ•œ๋‹ค. Store์™€ ๋ณ€๊ฒฝ๋กœ์ง์€ ๋ถ„๋ฆฌ๋˜์–ด์žˆ๋‹ค.
    ๋ฉ€ํ‹ฐ store๊ฐ€ ์žˆ๋‹ค. ํ•˜๋‚˜์˜ store๋งŒ ์žˆ๋‹ค.
    ๋ชจ๋“  stores๋Š” ์—ฐ๊ฒฐ์ด ๋Š์–ด์ง€๊ณ  ํ‰ํ‰ํ•˜๋‹ค. ์ˆ˜์ง์  reducer๊ฐ€ ์žˆ๋Š” ๋‹จ์ผ store์ด๋‹ค.
    ์‹ฑ๊ธ€ํ†ค dispatcher๊ฐ€ ์žˆ๋‹ค. dispatcher ๊ฐœ๋…์ด ์—†๋‹ค.
    React ์ปดํฌ๋„ŒํŠธ๋Š” store๋ฅผ ๊ตฌ๋…ํ•œ๋‹ค. Container ์ปดํฌ๋„ŒํŠธ๋Š” connect ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
  15. React Router V4์˜ ์žฅ์ ์€?

    ๋‹ค์Œ์€ React Router V4 ๋ชจ๋“ˆ์˜ ์ฃผ์š” ์žฅ์ ์ด๋‹ค.

    1. React Router v4(version 4)์—์„œ API๋Š” ์ปดํฌ๋„ŒํŠธ์™€ ๊ด€๋ จ๋œ ๊ฒƒ์ด๋‹ค. ๋ผ์šฐํ„ฐ๋Š” ํŠน์ • ํ•˜์œ„ ๋ผ์šฐํ„ฐ ์ปดํฌ๋„ŒํŠธ(<Route>)๋ฅผ ๊ฐ์‹ธ๋Š” ๋‹จ์ธ ์ปดํฌ๋„ŒํŠธ(<BrowserRouter>)๋กœ ์‹œ๊ฐํ™”ํ•  ์ˆ˜ ์žˆ๋‹ค.
    2. history๋ฅผ ์ˆ˜๋™์œผ๋กœ ์„ค์ •ํ•  ํ•„์š” ์—†๋‹ค. ๋ผ์šฐํ„ฐ ๋ชจ๋“ˆ์„ <BrowserRouter> ์ปดํฌ๋„ŒํŠธ๋กœ ๊ฒฝ๋กœ๋ฅผ ์ค„์ž„์œผ๋กœ์จ history๋ฅผ ๊ด€๋ฆฌํ•œ๋‹ค.
    3. ํŠน์ • ๋ผ์šฐํ„ฐ ๋ชจ๋“ˆ(์›น, ์ฝ”์–ด ๋˜๋Š” ๊ธฐ๋ณธ)๋งŒ ์ถ”๊ฐ€ํ•˜์—ฌ ์‘์šฉํ”„๋กœ๊ทธ๋žจ ํฌ๊ธฐ๊ฐ€ ์ค„์—ˆ๋‹ค.
  16. componentDidCatch ์ƒ๋ช…์ฃผ๊ธฐ ๋ฉ”์„œ๋“œ์— ๋Œ€ํ•ด์„œ ์„ค๋ช…ํ•  ์ˆ˜ ์žˆ๋‚˜?

    componentDidCatch ์ƒ๋ช…์ฃผ๊ธฐ ๋ฉ”์„œ๋“œ๋Š” ํ•˜์œ„ ์ปดํฌ๋„ŒํŠธ์—์„œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ํ˜ธ์ถœ๋œ๋‹ค. ์ด ๋ฉ”์„œ๋“œ๋Š” 2๊ฐœ์˜ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ๋ฐ›๋Š”๋‹ค.

    1. error: - ๋ณด๋‚ด์ง„ ์—๋Ÿฌ ๊ฐ์ฒด
    2. info: - ์˜ค๋ฅ˜๋ฅผ ๋ฐœ์ƒ์‹œํ‚จ ์ปดํฌ๋„ŒํŠธ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ํฌํ•จํ•œ componentStack key๊ฐ€ ์žˆ๋Š” ๊ฐ์ฒด

    ๋ฉ”์„œ๋“œ์˜ ๊ตฌ์กฐ๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

    componentDidCatch(error, info)
  17. ์–ด๋–ค ์—๋Ÿฌ ๋ฐ”์šด๋”๋ฆฌ(error boundary)์—์„œ ์žก์ง€ ๋ชปํ• ๊นŒ?

    ์•„๋ž˜์˜ ๊ฒฝ์šฐ๋Š” ์˜ค๋ฅ˜ ๊ฒฝ๊ณ„๊ฐ€ ์ž‘๋™ํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ์ด๋‹ค.

    1. Event handlers ์•ˆ์ชฝ์ผ ๊ฒฝ์šฐ
    2. setTimeout์ด๋‚˜ requestAnimationFrame ์ฝœ๋ฐฑ์„ ์‚ฌ์šฉํ•˜๋Š” ๋น„๋™๊ธฐ ์ฝ”๋“œ
    3. Server side rendering์„ ํ•  ๊ฒฝ์šฐ
    4. ์˜ค๋ฅ˜ ๊ฒฝ๊ณ„ ์ฝ”๋“œ ์ž์ฒด์—์„œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ ๊ฒฝ์šฐ
  18. ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ์— ์—๋Ÿฌ ๋ฐ”์šด๋”๋ฆฌ๊ฐ€ ํ•„์š”ํ•˜์ง€ ์•Š์€ ์ด์œ ๋Š”?

    ์—๋Ÿฌ ๋ฐ”์šด๋”๋ฆฌ๋Š” ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ๋‚ด์—์„œ ์˜ค๋ฅ˜๋ฅผ ์žก์•„๋‚ด์ง€ ๋ชปํ•œ๋‹ค. ๋ Œ๋”๋ง ๋ฉ”์„œ๋“œ๋‚˜ ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์„œ๋“œ์™€ ๋‹ค๋ฅด๊ฒŒ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ๋Š” ๋ Œ๋”๋งํ•˜๋Š” ๋™์•ˆ ๋ฐœ์ƒํ•˜๊ฑฐ๋‚˜ ํ˜ธ์ถœ๋˜์ง€ ์•Š๋Š”๋‹ค. ๋”ฐ๋ผ์„œ React๋Š” ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ์—์„œ ์ด๋Ÿฌํ•œ ์ข…๋ฅ˜์˜ ์˜ค๋ฅ˜๋ฅผ ๋ณต๊ตฌํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ๊ณ  ์žˆ๋‹ค. ๊ทธ๋ž˜๋„ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ๋‚ด์—์„œ ์˜ค๋ฅ˜๋ฅผ ์žก์•„๋‚ด์•ผ ํ•œ๋‹ค๋ฉด, ์•„๋ž˜์ฒ˜๋Ÿผ ์ผ๋ฐ˜ Javascript try / catch ๋ฌธ์„ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

    class MyComponent extends React.Component {
      constructor(props) {
        super(props);
        this.state = { error: null };
      }
    
      handleClick = () => {
        try {
          // Do something that could throw
        } catch (error) {
          this.setState({ error });
        }
      }
    
      render() {
        if (this.state.error) {
          return <h1>Caught an error.</h1>
        }
        return <div onClick={this.handleClick}>Click Me</div>
      }
    }

    ์œ„์˜ ์ฝ”๋“œ๋Š” ์—๋Ÿฌ ๋ฐ”์šด๋”๋ฆฌ ๋Œ€์‹  ๋ฐ”๋‹๋ผ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ try / catch ๋ธ”๋ก์„ ์‚ฌ์šฉํ•ด์„œ ์˜ค๋ฅ˜๋ฅผ ์žก์•„๋‚ด๊ณ  ์žˆ๋‹ค.

  19. try catch ๋ธ”๋ก๊ณผ ์—๋Ÿฌ ๋ฐ”์šด๋”๋ฆฌ์˜ ์ฐจ์ด์ ์€?

    Try catch ๋ธ”๋ก์€ ๋ช…๋ น ์ฝ”๋“œ์™€ ํ•จ๊ป˜ ์ž‘๋™ํ•˜์ง€๋งŒ, ์—๋Ÿฌ ๋ฐ”์šด๋”๋ฆฌ๋Š” ์„ ์–ธ ์ฝ”๋“œ๊ฐ€ ํ™”๋ฉด์— ๋ Œ๋”๋งํ•  ๋•Œ์ด๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, try catch ๋ธ”๋ก์€ ์•„๋ž˜ ๋ช…๋ น ์ฝ”๋“œ๊ฐ™์ด ์‚ฌ์šฉ๋œ๋‹ค.

    try {
      showButton();
    } catch (error) {
      // ...
    }

    ๋ฐ˜๋ฉด ์—๋Ÿฌ ๋ฐ”์šด๋”๋ฆฌ๋Š” ์„ ์–ธ์  ์ฝ”๋“œ๋ฅผ ์•„๋ž˜์™€ ๊ฐ™์ด ๊ฐ์‹ผ๋‹ค.

    <ErrorBoundary>
      <MyComponent />
    </ErrorBoundary>

    ๋”ฐ๋ผ์„œ tree์˜ ์–ด๋”˜๊ฐ€ setState๋กœ ์ธํ•ด์„œ componentDidUpdate ๋ฉ”์„œ๋“œ์—์„œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด, ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ์—๋Ÿฌ ๋ฐ”์šด๋”๋ฆฌ๋กœ ์ „ํŒŒ๋œ๋‹ค.

  20. react 16์—์„œ ์žกํžˆ์ง€ ์•Š๋Š” ์˜ค๋ฅ˜์˜ ๋™์ž‘์€?

    React 16์—์„œ ์—๋Ÿฌ ๋ฐ”์šด๋”๋ฆฌ์— ์žกํžˆ์ง€ ์•Š๋Š” ์˜ค๋ฅ˜๋Š” React ์ปดํฌ๋„ŒํŠธ tree๋ฅผ ๋งˆ์šดํŠธ ํ•ด์ œํ•œ๋‹ค. ์ด๋ ‡๊ฒŒ ๋˜๋Š” ์ด์œ ๋Š” ์†์ƒ๋œ UI๋ฅผ ์™„์ „ํžˆ ์ œ๊ฑฐํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ์†์ƒ๋œ UI๋ฅผ ๊ทธ๋Œ€๋กœ ๋‘๋Š” ๊ฒƒ์ด ๋” ์•ˆ ์ข‹๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๊ฒฐ์ œ ์•ฑ์ด ์ž˜๋ชป๋œ ๊ธˆ์•ก์„ ํ‘œ๊ธฐํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ๋ Œ๋”๋งํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์ด ๋‚ซ๋‹ค.

  21. ์—๋Ÿฌ ๋ฐ”์šด๋”๋ฆฌ์˜ ์ ์ ˆํ•œ ์œ„์น˜๋Š”?

    ์—๋Ÿฌ ๋ฐ”์šด๋”๋ฆฌ์˜ ์„ธ๋ถ„ํ™”๋Š” ํ”„๋กœ์ ํŠธ ํ•„์š”์— ๋”ฐ๋ผ ๊ฐœ๋ฐœ์ž์— ๋”ฐ๋ผ ๋‹ฌ๋ผ์งˆ ์ˆ˜ ์žˆ๋‹ค. ์•„๋ž˜์™€ ๊ฐ™์€ ์ ‘๊ทผ๋ฒ•์„ ์‹œํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค.

    1. ์ตœ์ƒ์œ„ ๋ผ์šฐํŠธ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ฐ์‹ธ์„œ ์ „์ฒด ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์— ๋Œ€ํ•œ ์ผ๋ฐ˜์ ์ธ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ํ‘œ์‹œํ•  ์ˆ˜ ์žˆ๋‹ค.
    2. ๊ฐ๊ฐ์˜ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์—๋Ÿฌ ๋ฐ”์šด๋”๋ฆฌ๋กœ ๊ฐ์‹ธ์„œ ๋‚˜๋จธ์ง€ ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์ด ์ถฉ๋Œํ•˜์ง€ ์•Š๋„๋ก ๋ณดํ˜ธํ•  ์ˆ˜ ์žˆ๋‹ค.
  22. ์—๋Ÿฌ ๋ฐ”์šด๋”๋ฆฌ์—์„œ ์ปดํฌ๋„ŒํŠธ ์Šคํƒ ์ถ”์ ์˜ ์žฅ์ ์€?

    ์—๋Ÿฌ ๋ฉ”์‹œ์ง€, ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์Šคํƒ๊ณผ ๋ณ„๊ฐœ๋กœ, React16์€ ์—๋Ÿฌ ๋ฐ”์šด๋”๋ฆฌ ๊ฐœ๋…์„ ์‚ฌ์šฉํ•˜์—ฌ ํŒŒ์ผ ์ด๋ฆ„๊ณผ ํ–‰ ๋ฒˆํ˜ธ๋ฅผ ํฌํ•จํ•œ ์ปดํฌ๋„ŒํŠธ ์Šคํƒ ์ถ”์ ์„ ํ‘œ์‹œํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, BuggyCounter ์ปดํฌ๋„ŒํŠธ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์ปดํฌ๋„ŒํŠธ ์Šคํƒ ์ถ”์ ์„ ํ‘œ์‹œํ•œ๋‹ค.

    stacktrace

  23. ํด๋ž˜์Šค ์ปดํฌ๋„ŒํŠธ์— ์ •์˜ํ•ด์•ผ ํ•˜๋Š” ๋ฉ”์„œ๋“œ๋Š” ๋ฌด์—‡์ธ๊ฐ€?

    render() ๋ฉ”์„œ๋“œ๋Š” ํด๋ž˜์Šค ์ปดํฌ๋„ŒํŠธ์—์„œ ์œ ์ผํ•˜๊ฒŒ ํ•„์š”ํ•œ ๋ฉ”์„œ๋“œ์ด๋‹ค. ์ฆ‰, render ๋ฉ”์„œ๋“œ๋ฅผ ์ œ์™ธํ•œ ๋ชจ๋“  ๋ฉ”์„œ๋“œ๋Š” ํด๋ž˜์Šค ์ปดํฌ๋„ŒํŠธ์—์„œ ์„ ํƒ์‚ฌํ•ญ์ด๋‹ค.

  24. render ๋ฉ”์„œ๋“œ์˜ return ๊ฐ€๋Šฅํ•œ ํƒ€์ž…์€?

    ์•„๋ž˜๋Š” render ๋ฉ”์„œ๋“œ์—์„œ ์‚ฌ์šฉ๋˜๊ฑฐ๋‚˜ return ๋˜๋Š” ๋ฆฌ์ŠคํŠธ์ž…๋‹ˆ๋‹ค.

    1. React elements: React๊ฐ€ DOM ๋…ธ๋“œ๋ฅผ ๋ Œ๋”๋งํ•˜๋„๋ก ์ง€์‹œํ•˜๋Š” Elements๋‹ค. <div/> ์™€ ๊ฐ™์€ html elements์™€ ์‚ฌ์šฉ์ž ์ •์˜ elements๊ฐ€ ํฌํ•จ๋œ๋‹ค.
    2. Arrays and fragments: ์—ฌ๋Ÿฌ elements๋ฅผ ๋ Œ๋”๋งํ•˜๊ธฐ ์œ„ํ•ด ์ด๋ฅผ ๊ฐ์‹ผ ๋ฐฐ์—ด๊ณผ Fragments๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
    3. Portals: ์ž์‹์€ ๋‹ค๋ฅธ DOM ํ•˜์œ„ ํŠธ๋ฆฌ๋กœ ๋ Œ๋”๋งํ•œ๋‹ค.
    4. String and numbers: DOM์—์„œ ๋ฌธ์ž์—ด๊ณผ ์ˆซ์ž๋ฅผ ๋ชจ๋‘ ํ…์ŠคํŠธ ๋…ธ๋“œ๋กœ ๋ Œ๋”๋งํ•œ๋‹ค.
    5. Booleans or null: ์•„๋ฌด๊ฒƒ๋„ ๋ Œ๋”๋งํ•˜์ง€ ์•Š์ง€๋งŒ, ์กฐ๊ฑด๋ถ€๋กœ ์ฝ˜ํ…์ธ ๋ฅผ ๋ Œ๋”๋งํ•  ๋•Œ ์‚ฌ์šฉ๋œ๋‹ค.
  25. constructor์˜ ์ฃผ์š” ๋ชฉ์ ์€?

    constructor๋Š” ์ฃผ๋กœ ๋‘ ๊ฐ€์ง€ ๋ชฉ์ ์œผ๋กœ ์‚ฌ์šฉ๋œ๋‹ค.

    1. this.state์— ๊ฐ์ฒด๋ฅผ ํ• ๋‹นํ•˜์—ฌ ๋กœ์ปฌ ์ƒํƒœ๋ฅผ ์ดˆ๊ธฐํ™”ํ•˜๊ธฐ ์œ„ํ•ด์„œ
    2. ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ๋ฉ”์„œ๋“œ๋ฅผ ์ธ์Šคํ„ด์Šค์— ๋ฐ”์ธ๋”ฉํ•˜๊ธฐ ์œ„ํ•ด์„œ

    ์˜ˆ๋ฅผ ๋“ค์–ด ์•„๋ž˜์˜ ์ฝ”๋“œ๋Š” ๋‘ ๊ฐ€์ง€ ๊ฒฝ์šฐ๋ฅผ ๋ชจ๋‘ ๋‹ค๋ฃจ๊ณ  ์žˆ๋‹ค.

    constructor(props) {
      super(props);
      // Don't call this.setState() here!
      this.state = { counter: 0 };
      this.handleClick = this.handleClick.bind(this);
    }
  26. React ์ปดํฌ๋„ŒํŠธ์˜ ์ƒ์„ฑ์ž๋ฅผ ์ •์˜ํ•ด์•ผ ํ•˜๋‚˜?

    ํ•„์ˆ˜๋Š” ์•„๋‹ˆ๋‹ค. ์ฆ‰, state๋ฅผ ์ดˆ๊ธฐํ™” ํ•˜์ง€ ์•Š๊ณ , ๋ฉ”์„œ๋“œ๋ฅผ ๋ฐ”์ธ๋”ฉํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด, React ์ปดํฌ๋„ŒํŠธ์— ์ƒ์„ฑ์ž๋ฅผ ๊ตฌํ˜„ํ•  ํ•„์š” ์—†๋‹ค.

โฌ† Back to Top

  1. default props๋ž€?

    defaultProps๋Š” ์ปดํฌ๋„ŒํŠธ ํด๋ž˜์Šค์˜ ์†์„ฑ์ด๋ฉฐ ํด๋ž˜์Šค์˜ ๊ธฐ๋ณธ props๋ฅผ ์„ค์ •ํ•œ๋‹ค. undefined props์— ์‚ฌ์šฉ๋˜์ง€๋งŒ, null props์—๋Š” ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š”๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๋ฒ„ํŠผ ์ปดํฌ๋„ŒํŠธ์˜ ์ƒ‰์ƒ default prop ๋งŒ๋“ค์–ด๋ณด์ž.

    class MyButton extends React.Component {
      // ...
    }
    
    MyButton.defaultProps = {
      color: 'red'
    };

    props.color๊ฐ€ ์—†๋‹ค๋ฉด ๊ธฐ๋ณธ๊ฐ’์€ '๋นจ๊ฐ„์ƒ‰'์œผ๋กœ ์„ค์ •๋œ๋‹ค. ์ฆ‰, color props์— ์ ‘๊ทผํ•˜๋ ค๊ณ  ํ•  ๋•Œ๋งˆ๋‹ค ๊ธฐ๋ณธ๊ฐ’์ด ์‚ฌ์šฉ๋œ๋‹ค.

    render() {
       return <MyButton /> ; // props.color will be set to red
     }

    Note: null ๊ฐ’์„ ์ œ๊ณตํ•˜๋ฉด null ๊ฐ’์ด ์œ ์ง€๋œ๋‹ค.

โฌ† Back to Top

  1. componentWillUnmount์—์„œ setState๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด ์•ˆ๋˜๋Š” ์ด์œ ๋Š”?

    ์ปดํฌ๋„ŒํŠธ ์ธ์Šคํ„ด์Šค๊ฐ€ ๋งˆ์šดํŠธ ํ•ด์ œ๋˜๋ฉด ๋‹ค์‹œ ๋งˆ์šดํŠธ๋  ์ˆ˜ ์—†์Œ์œผ๋กœ, componentWillUnmount()์—์„œ setState()๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด ์•ˆ ๋œ๋‹ค.

โฌ† Back to Top

  1. getDerivedStateFromError์˜ ๋ชฉ์ ์€?

    ์ด ๋ผ์ดํ”„์‚ฌ์ดํด ๋ฉ”์„œ๋“œ๋Š” ํ•˜์œ„ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์˜ค๋ฅ˜๋ฅผ ๋ฐœ์ƒํ•œ ํ›„ ํ˜ธ์ถœ๋œ๋‹ค. ๋งค๊ฐœ ๋ณ€์ˆ˜๋กœ ์˜ค๋ฅ˜๋ฅผ ์ˆ˜์‹ ํ•˜๊ณ  state๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๊ธฐ ์œ„ํ•œ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ๋ผ์ดํ”„์‚ฌ์ดํด ๋ฉ”์„œ๋“œ์˜ ์‚ฌ์šฉ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

    static getDerivedStateFromError(error)

    ์œ„์˜ ๋ผ์ดํ”„์‚ฌ์ดํด ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์˜ค๋ฅ˜ ๋ฐ”์šด๋”๋ฆฌ ์‚ฌ์šฉ ์˜ˆ์‹œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

    class ErrorBoundary extends React.Component {
      constructor(props) {
        super(props);
        this.state = { hasError: false };
      }
    
      static getDerivedStateFromError(error) {
        // Update state so the next render will show the fallback UI.
        return { hasError: true };
      }
    
      render() {
        if (this.state.hasError) {
          // You can render any custom fallback UI
          return <h1>Something went wrong.</h1>;
        }
    
        return this.props.children;
      }
    }

โฌ† Back to Top

  1. ๋ฆฌ๋ Œ๋”๋งํ•  ๋•Œ ๋ฉ”์„œ๋“œ์˜ ์ˆœ์„œ๋Š”?

    props ๋˜๋Š” state์˜ ๋ณ€๊ฒฝ์œผ๋กœ ์—…๋ฐ์ดํŠธ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค. ์•„๋ž˜์˜ ๋ฉ”์„œ๋“œ๋Š” ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ฆฌ๋ Œ๋”๋งํ•  ๋•Œ ํ˜ธ์ถœ๋˜๋Š” ์ˆœ์„œ์ด๋‹ค.

    1. static getDerivedStateFromProps()
    2. shouldComponentUpdate()
    3. render()
    4. getSnapshotBeforeUpdate()
    5. componentDidUpdate()

โฌ† Back to Top

  1. ์—๋Ÿฌ ํ•ธ๋“ค๋ง ์ค‘ ํ˜ธ์ถœ๋˜๋Š” ๋ฉ”์„œ๋“œ๋Š”?

    ์•„๋ž˜๋Š” ๋ฉ”์„œ๋“œ๋Š” ๋ Œ๋”๋ง ๋„์ค‘ ๋ผ์ดํ”„์‚ฌ์ดํด ๋ฉ”์„œ๋“œ ๋˜๋Š” ํ•˜์œ„ ์ปดํฌ๋„ŒํŠธ์˜ ์ƒ์„ฑ์ž์—์„œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ํ˜ธ์ถœ๋œ๋‹ค.

    1. static getDerivedStateFromError()
    2. componentDidCatch()

โฌ† Back to Top

  1. displayName ํด๋ž˜์Šค ์†์„ฑ์˜ ๋ชฉ์ ์€?

    displayName ๋ฌธ์ž์—ด์€ ๋ฉ”์‹œ์ง€ ๋””๋ฒ„๊น…์— ์‚ฌ์šฉ๋œ๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ •์˜ํ•˜๋Š” ํ•จ์ˆ˜ ๋˜๋Š” ํด๋ž˜์Šค ์ด๋ฆ„์—์„œ ์œ ์ถ”๋˜๋ฏ€๋กœ ๋ช…์‹œ์ ์œผ๋กœ ์„ค์ •ํ•  ํ•„์š” ์—†๋‹ค. ๋””๋ฒ„๊น… ๋ชฉ์ ์œผ๋กœ ๋‹ค๋ฅธ ์ด๋ฆ„์„ ํ‘œ์‹œํ•˜๊ฑฐ๋‚˜ HOC๋ฅผ ์ž‘์„ฑํ•  ๋•Œ ๋ช…์‹œ์ ์œผ๋กœ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๋””๋ฒ„๊น…์„ ์‰ฝ๊ฒŒ ํ•˜๋ ค๋ฉด withSubscription HOC์˜ ๊ฒฐ๊ณผ์ž„์„ ์•Œ๋ฆฌ๋Š” displayName์„ ์„ ํƒํ•œ๋‹ค.

    function withSubscription(WrappedComponent) {
      class WithSubscription extends React.Component {/* ... */}
      WithSubscription.displayName = `WithSubscription(${getDisplayName(WrappedComponent)})`;
      return WithSubscription;
    }
    
    function getDisplayName(WrappedComponent) {
      return WrappedComponent.displayName || WrappedComponent.name || 'Component';
    }

โฌ† Back to Top

  1. react ์‘์šฉํ”„๋กœ๊ทธ๋žจ์˜ ๋ธŒ๋ผ์šฐ์ € ์ง€์›์€ ์–ด๋””๊นŒ์ง€์ธ๊ฐ€?

    React๋Š” Internet Explorer 9 ์ด์ƒ์„ ํฌํ•จํ•˜์—ฌ ๋„๋ฆฌ ์‚ฌ์šฉ๋˜๋Š” ๋ชจ๋“  ๋ธŒ๋ผ์šฐ์ €๋ฅผ ์ง€์›ํ•˜์ง€๋งŒ, ์ผ๋ถ€ IE 9 ๋ฐ IE 10๊ณผ ๊ฐ™์€ ์ด์ „ ๋ธŒ๋ผ์šฐ์ €์—์„œ๋Š” ํด๋ฆฌํ•„์ด ํ•„์š”ํ•˜๋‹ค. es5-shim๊ณผ es5-sham ํด๋ฆฌํ•„์„ ์‚ฌ์šฉํ•˜๋ฉด ES5 ๋ฉ”์„œ๋“œ๋“ค์„ ์ง€์›ํ•˜์ง€ ์•Š๋Š” ์ด์ „ ๋ธŒ๋ผ์šฐ์ €์—์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค.

โฌ† Back to Top

  1. unmountComponentAtNode ๋ฉ”์„œ๋“œ์˜ ๋ชฉ์ ์€?

    ์ด ๋ฉ”์„œ๋“œ๋Š” react-dom ํŒจํ‚ค์ง€์—์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋ฉฐ, DOM์— ๋งˆ์šดํŠธ๋œ React ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ œ๊ฑฐํ•˜๊ณ  ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ์™€ state๋ฅผ ์ •๋ฆฌํ•œ๋‹ค. ์ปจํ…Œ์ด๋„ˆ์— ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋งˆ์šดํŠธ๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ ์ด ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด ์•„๋ฌด ์ž‘์—…๋„ ํ•˜์ง€ ์•Š๋Š”๋‹ค. ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋งˆ์šดํŠธ ํ•ด์ œ๋œ ๊ฒฝ์šฐ true, ๋งˆ์šดํŠธ ํ•ด์ œํ•  ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ false๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ๋ฉ”์„œ๋“œ ์‚ฌ์šฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

    ReactDOM.unmountComponentAtNode(container)

โฌ† Back to Top

  1. code-splitting์ด๋ž€?

    Code-Splitting์€ Webpack๊ณผ Browserify์™€ ๊ฐ™์€ ๋ฒˆ๋“ค๋Ÿฌ์—์„œ ์ง€์›ํ•˜๋Š” ๊ธฐ๋Šฅ์œผ๋กœ ๋Ÿฐํƒ€์ž„์— ๋™์ ์œผ๋กœ ๋กœ๋“œํ•  ์ˆ˜ ์žˆ๋Š” ์—ฌ๋Ÿฌ ๋ฒˆ๋“ค์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค. react ํ”„๋กœ์ ํŠธ๋Š” ๋™์  import() ๊ธฐ๋Šฅ์„ ํ†ตํ•ด code splitting์„ ์ง€์›ํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์•„๋ž˜์™€ ๊ฐ™์€ ์Šค๋‹ˆํ• ์ฝ”๋“œ์—์„œ๋Š” moduleA.js์™€ ๋ชจ๋“  ๊ณ ์œ ํ•œ ์ข…์†์„ฑ์„ ์‚ฌ์šฉ์ž๊ฐ€ '๋กœ๋“œ' ๋ฒ„ํŠผ์„ ํด๋ฆญํ–ˆ์„ ๋•Œ ๋กœ๋“œํ•˜๋Š” ๋ณ„๋„์˜ chuck๋กœ ๋งŒ๋“ ๋‹ค.

    moduleA.js

    const moduleA = 'Hello';
    
    export { moduleA };

    App.js

    import React, { Component } from 'react';
    
    class App extends Component {
      handleClick = () => {
        import('./moduleA')
          .then(({ moduleA }) => {
            // Use moduleA
          })
          .catch(err => {
            // Handle failure
          });
      };
    
      render() {
        return (
          <div>
            <button onClick={this.handleClick}>Load</button>
          </div>
        );
      }
    }
    
    export default App;

โฌ† Back to Top

  1. strict mode์˜ ์žฅ์ ์€?

    <StrictMode>๋Š” ์•„๋ž˜์™€ ๊ฐ™์€ ๊ฒฝ์šฐ์— ์œ ์šฉํ•˜๋‹ค.

    1. ์•ˆ์ „ํ•˜์ง€ ์•Š์€ ๋ผ์ดํ”„์‚ฌ์ดํด ๋ฉ”์„œ๋“œ๋ฅผ ๊ฐ€์ง„ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‹๋ณ„ํ•ด์ค€๋‹ค.
    2. ๋ ˆ๊ฑฐ์‹œ ๋ฌธ์ž์—ด ์ฐธ์กฐ API ์‚ฌ์šฉ์— ๋Œ€ํ•œ ๊ฒฝ๊ณ ๋ฅผ ํ•ด์ค€๋‹ค.
    3. ์˜ˆ์ƒ์น˜ ๋ชปํ•œ ๋ถ€์ž‘์šฉ์„ ๊ฐ์ง€ํ•œ๋‹ค.
    4. ๋ ˆ๊ฑฐ์‹œ ์ปจํ…์ŠคํŠธ API๋ฅผ ๊ฐ์ง€ํ•œ๋‹ค.
    5. ๋” ์ด์ƒ ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š” findDOMNode ์‚ฌ์šฉ์— ๋Œ€ํ•ด ๊ฒฝ๊ณ ๋ฅผ ํ•ด์ค€๋‹ค.

โฌ† Back to Top

  1. Keyed Fragments๋ž€?

    ๋ช…์‹œ์  <React.Fragment> ๊ตฌ๋ฌธ์œผ๋กœ ์„ ์–ธ๋œ Fragments์—๋Š” key๊ฐ€ ์žˆ์„ ์ˆ˜ ์žˆ๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์ปฌ๋ ‰์…˜์„ ๋ฐฐ์—ด์— ๋งคํ•‘ํ•œ๋‹ค.

    function Glossary(props) {
      return (
        <dl>
          {props.items.map(item => (
            // Without the `key`, React will fire a key warning
            <React.Fragment key={item.id}>
              <dt>{item.term}</dt>
              <dd>{item.description}</dd>
            </React.Fragment>
          ))}
        </dl>
      );
    }

    Note: key๋Š” Fragment์— ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋Š” ์œ ์ผํ•œ ์†์„ฑ์ด๋‹ค. ์•ž์œผ๋กœ๋Š”, ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ์™€ ๊ฐ™์€ ์ถ”๊ฐ€ ์†์„ฑ์ด ์ง€์›๋  ์ˆ˜ ์žˆ๋‹ค.

โฌ† Back to Top

  1. React๋Š” ๋ชจ๋“  HTML ์†์„ฑ์„ ์ง€์›ํ•˜๋‚˜?

    React 16 ๋ฒ„์ „์—์„œ, ํ‘œ์ค€๊ณผ ์‚ฌ์šฉ์ž ์ •์˜ DOM ์†์„ฑ ๋ชจ๋‘ ์ง€์›ํ•œ๋‹ค. React ์ปดํฌ๋„ŒํŠธ๋Š” ์ข…์ข… ์‚ฌ์šฉ์ž ์ •์˜์™€ DOM ๊ด€๋ จ props๋ฅผ ๋ชจ๋‘ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ, React๋Š” DOM API์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ camelCase ๊ทœ์น™์„ ์‚ฌ์šฉํ•œ๋‹ค. ํ‘œ์ค€ HTML ์†์„ฑ์„ ์‚ฌ์šฉํ•˜๊ณ  props๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์€ ์˜ˆ์‹œ์ด๋‹ค.

    <div tabIndex="-1" />      // Just like node.tabIndex DOM API
    <div className="Button" /> // Just like node.className DOM API
    <input readOnly={true} />  // Just like node.readOnly DOM API

    props๋Š” ํŠน๋ณ„ํ•œ ๊ฒฝ์šฐ๋Š” ์ œ์™ธํ•˜๊ณ  ํ•ด๋‹น HTML ์†์„ฑ๊ณผ ์œ ์‚ฌํ•˜๊ฒŒ ์ž‘๋™ํ•œ๋‹ค. ๋˜ํ•œ ๋ชจ๋“  SVG ์†์„ฑ์„ ์ง€์›ํ•œ๋‹ค.

โฌ† Back to Top

  1. HOC์˜ ํ•œ๊ณ„๋Š”?

    ๊ณ ์ฐจ ์ปดํฌ๋„ŒํŠธ๋Š” ์žฅ์ ๊ณผ๋Š” ๋ฌด๊ด€ํ•˜๊ฒŒ ๋ช‡ ๊ฐ€์ง€ ๊ฒฝ๊ณ  ์‚ฌํ•ญ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

    1. render ๋ฉ”์„œ๋“œ ์•ˆ์—์„œ ์‚ฌ์šฉํ•ด์„œ๋Š” ์•ˆ ๋œ๋‹ค. : ์ปดํฌ๋„ŒํŠธ์˜ redner ๋ฉ”์„œ๋“œ ๋‚ด์—์„œ HOC๋ฅผ ์ ์šฉํ•˜๋Š” ๊ฒƒ์€ ์ข‹์ง€ ์•Š๋‹ค.

      render() {
        // ์ƒˆ๋กœ์šด ๋ฒ„์ „์˜ EnhancedComponent๊ฐ€ ๋ Œ๋”๋งํ•  ๋•Œ๋งˆ๋‹ค ์ƒ์„ฑ๋œ๋‹ค.
        // EnhancedComponent1 !== EnhancedComponent2
        const EnhancedComponent = enhance(MyComponent);
        // That causes the entire subtree to unmount/remount each time!
        return <EnhancedComponent />;
      }

      ์œ„์˜ ์ฝ”๋“œ๋Š” ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋‹ค์‹œ ๋งˆ์šดํŠธํ•˜๋ฉด ํ•ด๋‹น ์ปดํฌ๋„ŒํŠธ ๋ฐ ๋ชจ๋“  ํ•˜์œ„ ์ปดํฌ๋„ŒํŠธ์˜ state๋ฅผ ์žƒ์–ด๋ฒ„๋ ค ์„ฑ๋Šฅ์— ์˜ํ–ฅ์„ ๋ฏธ์นœ๋‹ค. ๋Œ€์‹  ์ปดํฌ๋„ŒํŠธ๊ฐ€ ํ•œ ๋ฒˆ๋งŒ ์ž‘์„ฑ๋˜๋„๋ก ์ปดํฌ๋„ŒํŠธ ์ •์˜ ์™ธ๋ถ€์—์„œ HOC๋ฅผ ์ ์šฉํ•˜๋ฉด ๋œ๋‹ค.

    2. static ๋ฉ”์„œ๋“œ๋ฅผ ๋ณต์‚ฌํ•ด์•ผ ํ•œ๋‹ค. : HOC๋ฅผ ์ƒˆ๋กœ์šด ์ปดํฌ๋„ŒํŠธ์— ์ ์šฉํ•  ๋•Œ ์ƒˆ๋กœ์šด ์ปดํฌ๋„ŒํŠธ์—๋Š” ์›๋ณธ ์ปดํฌ๋„ŒํŠธ์˜ static ๋ฉ”์„œ๋“œ๊ฐ€ ์—†๋‹ค.

      // staic ๋ฉ”์„œ๋“œ ์ •์˜
      WrappedComponent.staticMethod = function() {/*...*/}
      // HOC ์ ์šฉ
      const EnhancedComponent = enhance(WrappedComponent);
      
      // enhanced component๋Š” static ๋ฉ”์„œ๋“œ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์ง€ ์•Š๋‹ค.
      typeof EnhancedComponent.staticMethod === 'undefined' // true

      ๋ฐ˜ํ™˜ํ•˜๊ธฐ ์ „์— ๋ฉ”์„œ๋“œ๋ฅผ ์ปจํ…Œ์ด๋„ˆ์— ๋ณต์‚ฌํ•˜์—ฌ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค.

      function enhance(WrappedComponent) {
        class Enhance extends React.Component {/*...*/}
        // Must know exactly which method(s) to copy :(
        Enhance.staticMethod = WrappedComponent.staticMethod;
        return Enhance;
      }
    3. Refs๊ฐ€ ์ „๋‹ฌ๋˜์ง€ ์•Š๋Š”๋‹ค. : HOC์˜ ๊ฒฝ์šฐ ๋ชจ๋“  props๋ฅผ ๋ž˜ํ•‘ ๋œ ์ปดํฌ๋„ŒํŠธ๋กœ ์ „๋‹ฌํ•ด์•ผ ํ•˜์ง€๋งŒ refs๋Š” ์ ์šฉ๋˜์ง€ ์•Š๋Š”๋‹ค. ref๋Š” ์‹ค์ œ๋กœ key์™€ ๋น„์Šทํ•œ props์ด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ์ด ๊ฒฝ์šฐ์—๋Š” React.forwardRef API ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

โฌ† Back to Top

  1. ๊ฐœ๋ฐœ์ž ๋„๊ตฌ์—์„œ forwardRefs๋ฅผ ๋””๋ฒ„๊น…ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    React.forwardRef ๋Š” ๋ Œ๋”๋ง ํ•จ์ˆ˜๋ฅผ ๋งค๊ฐœ ๋ณ€์ˆ˜๋กœ ๋ฐ›๊ณ  ์žˆ์œผ๋ฉฐ, ๊ฐœ๋ฐœ์ž ๋„๊ตฌ๋Š” ์ด ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ref ์ „๋‹ฌ ์ปดํฌ๋„ŒํŠธ์— ํ‘œ์‹œํ•  ๋‚ด์šฉ์„ ๊ฒฐ์ •ํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๋ Œ๋”๋ง ํ•จ์ˆ˜์˜ ์ด๋ฆ„์„ ์ง€์ •ํ•˜์ง€ ์•Š๊ฑฐ๋‚˜ displayName ์†์„ฑ์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š์œผ๋ฉด ๊ฐœ๋ฐœ์ž ๋„๊ตฌ์—์„œ โ€ForwardRefโ€๋กœ ํ‘œ์‹œ๋œ๋‹ค.

    const WrappedComponent = React.forwardRef((props, ref) => {
      return <LogProps {...props} forwardedRef={ref} />;
    });

    ๊ทธ๋Ÿฌ๋‚˜ ๋ Œ๋”๋ง ํ•จ์ˆ˜์˜ ์ด๋ฆ„์„ ์ง€์ •ํ•˜๊ฒŒ ๋˜๋ฉด **โ€ForwardRef(myFunction)โ€**์œผ๋กœ ๋‚˜ํƒ€๋‚œ๋‹ค.

    const WrappedComponent = React.forwardRef(
      function myFunction(props, ref) {
        return <LogProps {...props} forwardedRef={ref} />;
      }
    );

    ๋Œ€์•ˆ์œผ๋กœ, forwardRef ํ•จ์ˆ˜์— displayName ์†์„ฑ์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

    function logProps(Component) {
      class LogProps extends React.Component {
        // ...
      }
    
      function forwardRef(props, ref) {
        return <LogProps {...props} forwardedRef={ref} />;
      }
    
      // Give this component a more helpful display name in DevTools.
      // e.g. "ForwardRef(logProps(MyComponent))"
      const name = Component.displayName || Component.name;
      forwardRef.displayName = `logProps(${name})`;
    
      return React.forwardRef(forwardRef);
    }

โฌ† Back to Top

  1. ์ปดํฌ๋„ŒํŠธ props์˜ ๊ธฐ๋ณธ๊ฐ’์€ true์ธ๊ฐ€?

    prop์— ์•„๋ฌด ๊ฐ’๋„ ์ „๋‹ฌํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด, ๊ธฐ๋ณธ๊ฐ’์€ true์ด๋‹ค. ์ด ๋™์ž‘์€ HTML์˜ ๋™์ž‘๊ณผ ์ผ์น˜ํ•˜๊ฒŒ ํ•  ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ์•„๋ž˜์™€ ๊ฐ™์€ ํ‘œํ˜„์‹์€ ๋™์ผํ•œ ํ‘œํ˜„์ด๋‹ค.

    <MyInput autocomplete />
    
    <MyInput autocomplete={true} />

    Note: ์ด ๋ฐฉ๋ฒ•์€ ES6 ๊ฐ์ฒด ์†๊ธฐ (์˜ˆ, {name: name}์˜ ์•ฝ์ž๋Š” {name})์™€ ํ˜ผ๋™ํ•  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.

โฌ† Back to Top

  1. NextJS๋Š” ๋ฌด์—‡์ด๋ฉฐ, ์ฃผ์š”ํ•œ ๊ธฐ๋Šฅ์€?

    Next.js๋Š” React๋กœ ๋งŒ๋“ค์–ด์ง„ ์ •์ , ์„œ๋ฒ„ ๋ Œ๋”๋ง ์‘์šฉํ”„๋กœ๊ทธ๋žจ์„ ์œ„ํ•œ ๋Œ€์ค‘์ ์ด๊ณ  ๊ฐ€๋ฒผ์šด ํ”„๋ ˆ์ž„ ์›Œํฌ์ด๋‹ค. ๋˜ํ•œ ์Šคํƒ€์ผ๋ง๊ณผ ๋ผ์šฐํŒ… ์†”๋ฃจ์…˜์„ ์ œ๊ณตํ•œ๋‹ค. ์•„๋ž˜๋Š” NextJS๊ฐ€ ์ œ๊ณตํ•˜๋Š” ์ฃผ์š” ๊ธฐ๋Šฅ์ด๋‹ค.

    1. ๊ธฐ๋ณธ์ ์œผ๋กœ ์„œ๋ฒ„ ๋ Œ๋”๋ง
    2. ๋น ๋ฅธ ํŽ˜์ด์ง€ ๋กœ๋”ฉ์„ ์œ„ํ•œ ์ž๋™ ์ฝ”๋“œ ๋ถ„ํ• 
    3. ๊ฐ„๋‹จํ•œ ํด๋ผ์ด์–ธํŠธ ์‚ฌ์ด๋“œ ๋ผ์šฐํŒ…(page๊ธฐ๋ฐ˜)
    4. HMR์„ ์ง€์›ํ•˜๋Š” ์›นํŒฉ ๊ธฐ๋ฐ˜ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ
    5. Express ๋˜๋Š” ๋‹ค๋ฅธ Node.js HTTP ์„œ๋ฒ„๋กœ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.
    6. ๊ณ ์œ ํ•œ Babel ๋ฐ Webpack ๊ตฌ์„ฑ์œผ๋กœ ์‚ฌ์šฉ์ž ์ •์˜๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.

โฌ† Back to Top

  1. ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ๋ฅผ ์ปดํฌ๋„ŒํŠธ์— ์–ด๋–ป๊ฒŒ ์ „๋‹ฌํ•˜๋‚˜?

    ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ๋ฐ ํ•จ์ˆ˜๋ฅผ ํ•˜์œ„ ์ปดํฌ๋„ŒํŠธ์— props๋กœ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋‹ค. ์•„๋ž˜์™€ ๊ฐ™์ด ์ž์‹ ์ปดํฌ๋„ŒํŠธ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

    <button onClick={this.handleClick}>
    

โฌ† Back to Top

  1. render ๋ฉ”์„œ๋“œ์—์„œ ํ™”์‚ดํ‘œ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹์€๊ฐ€?

    ์˜ˆ, ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ์ฝœ๋ฐฑ ํ•จ์ˆ˜์— ๋งค๊ฐœ ๋ณ€์ˆ˜๋ฅผ ์ „๋‹ฌํ•˜๋Š” ๊ฐ€์žฅ ์‰ฌ์šด ๋ฐฉ๋ฒ•์ด๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์‚ฌ์šฉํ•˜๋Š” ๋™์•ˆ ์„ฑ๋Šฅ์„ ์ตœ์ ํ™”ํ•ด์•ผ ํ•œ๋‹ค.

    class Foo extends Component {
      handleClick() {
        console.log('Click happened');
      }
      render() {
        return <button onClick={() => this.handleClick()}>Click Me</button>;
      }
    }

    Note: render ๋ฉ”์„œ๋“œ์—์„œ ํ™”์‚ดํ‘œ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ Œ๋”๋ง ๋  ๋•Œ๋งˆ๋‹ค ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ์ด ์ƒ์„ฑ๋˜์–ด ์„ฑ๋Šฅ์— ์˜ํ–ฅ์„ ์ค„ ์ˆ˜ ์žˆ๋‹ค.

โฌ† Back to Top

  1. ํ•จ์ˆ˜๊ฐ€ ์—ฌ๋Ÿฌ ๋ฒˆ ํ˜ธ์ถœ๋˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    onClick ๋˜๋Š” onScroll๊ณผ ๊ฐ™์€ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์ฝœ๋ฐฑ์ด ๋„ˆ๋ฌด ๋นจ๋ฆฌ ๋ฐœ์ƒํ•˜์ง€ ์•Š๋„๋ก ํ•˜๋ ค๋ฉด ์ฝœ๋ฐฑ ์‹คํ–‰ ์†๋„๋ฅผ ์ œํ•œํ•  ์ˆ˜ ์žˆ๋‹ค. ์•„๋ž˜์™€ ๊ฐ™์€ ๋ฐฉ๋ฒ•์œผ๋กœ ๊ฐ€๋Šฅํ•˜๋‹ค.

    1. Throttling: ์‹œ๊ฐ„์„ ๊ธฐ๋ฐ˜์œผ๋กœ ๋นˆ๋„์— ๋”ฐ๋ผ ๋ณ€๊ฒฝ์ด ๋œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, lodash์˜ _.throttle ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
    2. Debouncing: ์ผ์ • ๊ธฐ๊ฐ„ ์‚ฌ์šฉํ•˜์ง€ ์•Š์œผ๋ฉด ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ์‹คํ–‰ํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, lodash์˜ _.debounce ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
    3. RequestAnimationFrame throttling: requestAnimationFrame์— ๋”ฐ๋ผ ๋ณ€๊ฒฝ๋œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, lodash์˜ raf-schd ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

โฌ† Back to Top

  1. JSX๊ฐ€ Injection ๊ณต๊ฒฉ์€ ๋ง‰๋Š” ๋ฐฉ๋ฒ•์€?

    React DOM์€ ๋ Œ๋”๋งํ•˜๊ธฐ ์ „์— JSX์— ํฌํ•จ๋œ ๋ชจ๋“  ๊ฐ’์€ escape ์ฒ˜๋ฆฌํ•œ๋‹ค. ๋”ฐ๋ผ์„œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์•„๋ฌด๊ฒƒ๋„ ์ฃผ์ž…๋˜์ง€ ์•Š๋Š” ๊ฒƒ์„ ๋ณด์žฅํ•œ๋‹ค. ๋ชจ๋“  ๊ฒƒ์ด ๋ Œ๋”๋ง๋˜๊ธฐ ์ „์— ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜๋œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉ์ž ์ž…๋ ฅ์„ ํฌํ•จํ•  ์ˆ˜ ์žˆ๋‹ค.

    const name = response.potentiallyMaliciousInput;
    const element = <h1>{name}</h1>;

    ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ XSS(Cross-site-scripting) ๊ณต๊ฒฉ์„ ๋ฐฉ์ง€ํ•  ์ˆ˜ ์žˆ๋‹ค.

โฌ† Back to Top

  1. ๋ Œ๋”๋ง ๋œ ์š”์†Œ๋Š” ์–ด๋–ป๊ฒŒ ์—…๋ฐ์ดํŠธํ•˜๋‚˜?

    ์ƒˆ๋กœ ์ž‘์„ฑ๋œ ์š”์†Œ๋ฅผ ReactDOM์˜ render ๋ฉ”์„œ๋“œ์— ์ „๋‹ฌํ•˜์—ฌ UI(๋ Œ๋”๋ง ๋œ ์š”์†Œ๋กœ ํ‘œ์‹œ)๋ฅผ ์—…๋ฐ์ดํŠธ ํ•  ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๋˜‘๋”ฑ๊ฑฐ๋ฆฌ๋Š” ์‹œ๊ณ„๋ฅผ ์˜ˆ๋กœ ๋“ค์ž๋ฉด, render ๋ฉ”์„œ๋“œ๋ฅผ ์—ฌ๋Ÿฌ ๋ฒˆ ํ˜ธ์ถœํ•˜์—ฌ ์‹œ๊ฐ„์„ ์—…๋ฐ์ดํŠธํ•œ๋‹ค.

    function tick() {
      const element = (
        <div>
          <h1>Hello, world!</h1>
          <h2>It is {new Date().toLocaleTimeString()}.</h2>
        </div>
      );
      ReactDOM.render(element, document.getElementById('root'));
    }
    
    setInterval(tick, 1000);

โฌ† Back to Top

  1. props๊ฐ€ ์ฝ๊ธฐ ์ „์šฉ์ด์–ด์•ผ ํ•˜๋Š” ์ด์œ ๋Š”?

    ์ปดํฌ๋„ŒํŠธ๋ฅผ ํ•จ์ˆ˜๋‚˜ ํด๋ž˜์Šค๋กœ ์„ ์–ธํ•  ๋•Œ ์ž์‹ ์˜ props๋ฅผ ์ˆ˜์ •ํ•ด์„œ๋Š” ์•ˆ ๋œ๋‹ค. ์•„๋ž˜์˜ capital ํ•จ์ˆ˜๋ฅผ ์˜ˆ๋กœ ๋“ค์–ด๋ณด์ž.

    function capital(amount, interest) {
       return amount + interest;
    }

    ์œ„์˜ ํ•จ์ˆ˜๋Š” ์ž…๋ ฅ์„ ๋ณ€๊ฒฝํ•˜์ง€ ์•Š์œผ๋ฉด์„œ ํ•ญ์ƒ ๋™์ผํ•œ ์ž…๋ ฅ์— ๋Œ€ํ•ด ๋™์ผํ•œ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๊ธฐ ๋•Œ๋ฌธ์— "์ˆœ์ˆ˜"ํ•˜๋‹ค๊ณ  ํ•œ๋‹ค. ๋”ฐ๋ผ์„œ, React์—๋Š” "๋ชจ๋“  React ์ปดํฌ๋„ŒํŠธ๋Š” props์™€ ๊ด€๋ จ๋œ ๊ฒƒ์€ ์ˆœ์ˆ˜ํ•จ์ˆ˜์ฒ˜๋Ÿผ ์ž‘๋™ํ•ด์•ผ ํ•œ๋‹ค." ๋ผ๋Š” ๋‹จ์ผ ๊ทœ์น™์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.

โฌ† Back to Top

  1. state updates๊ฐ€ ์–ด๋–ป๊ฒŒ ๋ณ‘ํ•ฉ๋˜๋‚˜?

    ์ปดํฌ๋„ŒํŠธ์—์„œ setState()๋ฅผ ์‹คํ–‰ํ•˜๋ฉด, React ์‚ฌ์šฉ์ž๊ฐ€ ์ œ๊ณตํ•œ object๋ฅผ ํ˜„์žฌ state๋กœ ๋ณ‘ํ•ฉํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๊ฒŒ์‹œ๋ฌผ ๋ฐ ๋Œ“๊ธ€ ์„ธ๋ถ€ ์ •๋ณด๋ฅผ state ๋ณ€์ˆ˜๋กœ ์‚ฌ์šฉํ•˜๋Š” ํŽ˜์ด์Šค๋ถ ์‚ฌ์šฉ์ž๋ฅผ ์‚ดํŽด๋ณด์ž.

      constructor(props) {
        super(props);
        this.state = {
          posts: [],
          comments: []
        };
      }

    ์•„๋ž˜์™€ ๊ฐ™์ด ๋ณ„๋„์˜ setState()๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ๋…๋ฆฝ์ ์œผ๋กœ ์—…๋ฐ์ดํŠธํ•  ์ˆ˜ ์žˆ๋‹ค.

     componentDidMount() {
        fetchPosts().then(response => {
          this.setState({
            posts: response.posts
          });
        });
    
        fetchComments().then(response => {
          this.setState({
            comments: response.comments
          });
        });
      }

    ์œ„์˜ ์ฝ”๋“œ ์Šค๋‹ˆํ•์—์„œ ์–ธ๊ธ‰ํ–ˆ๋“ฏ์ด this.setState({comments})๋Š” ๊ฒŒ์‹œ๋ฌผ ๋ณ€์ˆ˜๋ฅผ ์ˆ˜์ •ํ•˜๊ฑฐ๋‚˜ ๋ฐ”๊พธ์ง€ ์•Š๊ณ  comments ๋ณ€์ˆ˜๋งŒ ์—…๋ฐ์ดํŠธํ•œ๋‹ค.

โฌ† Back to Top

  1. ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ์— ์ธ์ˆ˜๋ฅผ ์–ด๋–ป๊ฒŒ ๋„˜๊ธฐ๋‚˜?

    ๋ฐ˜๋ณต ๋˜๋Š” ๋ฃจํ”„๋ฅผ ๋„๋Š” ์ค‘์— ์ถ”๊ฐ€์ ์ธ ๋งค๊ฐœ ๋ณ€์ˆ˜๋ฅผ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ์— ์ „๋‹ฌํ•˜๋Š” ๊ฒƒ์ด ์ผ๋ฐ˜์ ์ด๋‹ค. ํ™”์‚ดํ‘œ ํ•จ์ˆ˜ ๋˜๋Š” ๋ฉ”์„œ๋“œ ๋ฐ”์ธ๋“œ๋กœ ๊ฐ€๋Šฅํ•˜๋‹ค. ๊ทธ๋ฆฌ๋“œ์—์„œ ์—…๋ฐ์ดํŠธ๋œ ์‚ฌ์šฉ์ž ์ •๋ณด๋กœ ์˜ˆ๋ฅผ ๋“ค์–ด ๋ณด์ž.

    <button onClick={(e) => this.updateUser(userId, e)}>Update User details</button>
    <button onClick={this.updateUser.bind(this, userId)}>Update User details</button>

    ๋‘ ๊ฐ€์ง€ ์ ‘๊ทผ๋ฐฉ์‹์—์„œ, ํ•ฉ์„ฑ ์ธ์ˆ˜ e๋Š” ๋‘ ๋ฒˆ์งธ ์ธ์ž๋กœ ์ „๋‹ฌ๋œ๋‹ค. ํ™”์‚ดํ‘œ ํ•จ์ˆ˜์˜ ๊ฒฝ์šฐ์—๋Š” ๋ช…์‹œ์ ์œผ๋กœ ์ „๋‹ฌํ•ด ์ฃผ์–ด์•ผ ํ•˜๋ฉฐ, ๋ฉ”์„œ๋“œ ๋ฐ”์ธ๋“œ๋Š” ์ž๋™์œผ๋กœ ์ „๋‹ฌ๋œ๋‹ค.

โฌ† Back to Top

  1. ์ปดํฌ๋„ŒํŠธ ๋ Œ๋”๋ง์„ ๋ง‰๋Š” ๋ฐฉ๋ฒ•์€?

    ํŠน์ • ์กฐ๊ฑด์— ๋”ฐ๋ผ null์„ ๋ฐ˜ํ™˜ํ•˜์—ฌ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ Œ๋”๋ง ๋˜์ง€ ์•Š๋„๋ก ํ•  ์ˆ˜ ์žˆ๋‹ค. ์•„๋ž˜์™€ ๊ฐ™์ด ์กฐ๊ฑด๋ถ€๋กœ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ Œ๋”๋งํ•  ์ˆ˜ ํ•  ์ˆ˜ ์žˆ๋‹ค.

    function Greeting(props) {
      if (!props.loggedIn) {
        return null;
      }
    
      return (
        <div className="greeting">
          welcome, {props.name}
        </div>
      );
    }
    class User extends React.Component {
      constructor(props) {
        super(props);
        this.state = {loggedIn: false, name: 'John'};
      }
    
      render() {
       return (
           <div>
             //Prevent component render if it is not loggedIn
             <Greeting loggedIn={this.state.loggedIn} />
             <UserDetails name={this.state.name}>
           </div>
       );
      }

    ์œ„์˜ ์˜ˆ์ œ์—์„œ, greeting ์ปดํฌ๋„ŒํŠธ๋Š” ์กฐ๊ฑด๋ฌธ์„ ์ ์šฉํ•˜๊ณ  null ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•˜์—ฌ ๋ Œ๋”๋ง ๋ถ€๋ถ„์€ ๊ฑด๋„ˆ๋›ด๋‹ค.

โฌ† Back to Top

  1. index๋ฅผ ํ‚ค๋กœ ์•ˆ์ „ํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ์กฐ๊ฑด์€?

    index๋ฅผ ํ‚ค๋กœ ์•ˆ์ „ํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ 3๊ฐ€์ง€ ์กฐ๊ฑด์ด ์žˆ๋‹ค.

    1. ๋ชฉ๋ก๊ณผ ํ•ญ๋ชฉ์€ ์ •์ ์ด๋‹ค. ๊ณ„์‚ฐ๋˜์ง€ ์•Š๊ณ  ๋ณ€๊ฒฝ ์•Š์„ ๊ฒฝ์šฐ.
    2. ๋ชฉ๋ก์— ์žˆ๋Š” ํ•ญ๋ชฉ๋“ค์ด id๊ฐ€ ์—†์„ ๊ฒฝ์šฐ.
    3. ๋ชฉ๋ก์ด ๋‹ค์‹œ ์ •๋ ฌ๋˜๊ฑฐ๋‚˜ ํ•„ํ„ฐ๋ง ๋˜์ง€ ์•Š์„ ๊ฒฝ์šฐ

โฌ† Back to Top

  1. ํ‚ค๊ฐ€ ์ „์ฒด์—์„œ ๊ณ ์œ ํ•ด์•ผ ํ•˜๋‚˜?

    ๋ฐฐ์—ด ๋‚ด์—์„œ ์‚ฌ์šฉ๋˜๋Š” ํ‚ค๋Š” ํ˜•์ œ ์‚ฌ์ด์—์„œ ๊ณ ์œ ํ•ด์•ผ ํ•˜์ง€๋งŒ ์ „์ฒด์ ์œผ๋กœ๋Š” ๊ณ ์œ ํ•  ํ•„์š” ์—†๋‹ค. ์ฆ‰, ๋‘ ๊ฐœ์˜ ๋‹ค๋ฅธ ๋ฐฐ์—ด์—์„œ ๋™์ผํ•œ ํ‚ค๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์•„๋ž˜์˜ Book ์ปดํฌ๋„ŒํŠธ๋Š” ๋‹ค๋ฅธ ๋ฐฐ์—ด ๋‘ ๊ฐœ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋‹ค.

    function Book(props) {
      const index = (
        <ul>
          {props.pages.map((page) =>
            <li key={page.id}>
              {page.title}
            </li>
          )}
        </ul>
      );
      const content = props.pages.map((page) =>
        <div key={page.id}>
          <h3>{page.title}</h3>
          <p>{page.content}</p>
          <p>{page.pageNumber}</p>
        </div>
      );
      return (
        <div>
          {index}
          <hr />
          {content}
        </div>
      );
    }

โฌ† Back to Top

  1. Form ์ฒ˜๋ฆฌ์— ๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉ๋˜๋Š” ์„ ํƒ์ง€๋Š”?

    Formik์€ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ, ๋ฐฉ๋ฌธ ํŽ˜์ด์ง€ ์ถ”์ , form ์ œ์ถœ ์ฒ˜๋ฆฌ์™€ ๊ฐ™์€ ์†”๋ฃจ์…˜์„ ์ œ๊ณตํ•˜๋Š” react ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋‹ค. ๊ตฌ์ฒด์ ์œผ๋กœ ๋‹ค๋ฆ„๊ณผ ๊ฐ™์ด ๋ถ„๋ฅ˜ํ•  ์ˆ˜ ์žˆ๋‹ค.

    1. form state ๊ฐ’ ๊ฐ€์ ธ์˜ค๊ธฐ
    2. ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ์™€ ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€
    3. form ์ œ์ถœ ์ฒ˜๋ฆฌ

    ์ตœ์†Œํ•œ์˜ API๋กœ ํ™•์žฅํ•  ์ˆ˜ ์žˆ๊ณ  ์„ฑ๋Šฅ์ด ๋›ฐ์–ด๋‚œ form ํ—ฌํผ๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ๊ท€์ฐฎ์€ ๊ฒƒ์„ ํ•ด๊ฒฐํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋œ๋‹ค.

โฌ† Back to Top

  1. redux form ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ณด๋‹ค formik์˜ ์žฅ์ ์€?

    ๋‹ค์Œ์€ redux form ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ณด๋‹ค formik์„ ๊ถŒ์žฅํ•˜๋Š” ์ฃผ์š” ์ด์œ ์ด๋‹ค.

    1. form state๋Š” ๋ณธ์งˆ์ ์œผ๋กœ ๋‹จ๊ธฐ์ ์ด๋ฉฐ ๋กœ์ปฌ์ด๋ฏ€๋กœ Redux(๋˜๋Š” ๋ชจ๋“  ์ข…๋ฅ˜์˜ Flux ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ) ์—์„œ ์ถ”์ ํ•  ํ•„์š”๊ฐ€ ์—†๋‹ค.
    2. Redux-Form์€ EVERY SINGLE KEYSTROKE์—์„œ ์ „์ฒด ์ตœ์ƒ์œ„ Redux reducer๋ฅผ ์—ฌ๋Ÿฌ ๋ฒˆ ํ˜ธ์ถœํ•œ๋‹ค. ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ํฐ ์•ฑ์˜ ์ž…๋ ฅ ๋Œ€๊ธฐ ์‹œ๊ฐ„์ด ๋Š˜์–ด๋‚œ๋‹ค.
    3. Redux-Form์€ 22.5 kB๋กœ ์ถ•์†Œ๋œ gzip์ธ ๋ฐ˜๋ฉด Formik์€ 12.7 kB์ด๋‹ค.

โฌ† Back to Top

  1. ์ƒ์†ํ•  ํ•„์š”๊ฐ€ ์—†๋Š” ์ด์œ ๋Š”?

    React์—์„œ ์ปดํฌ๋„ŒํŠธ ๊ฐ„ ์ฝ”๋“œ๋ฅผ ์žฌ์‚ฌ์šฉํ•˜๋ ค๋ฉด ์ƒ์† ๋Œ€์‹  composition์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค. Props์™€ composition ๋ชจ๋‘ ๋ช…์‹œ์ ์ด๊ณ  ์•ˆ์ „ํ•œ ๋ฐฉ์‹์œผ๋กœ ์ปดํฌ๋„ŒํŠธ์˜ ํ˜•ํƒœ์™€ ๊ธฐ๋Šฅ์„ ์ปค์Šคํ…€ํ•˜๋Š”๋ฐ ํ•„์š”ํ•œ ๋ชจ๋“  ์œ ์—ฐ์„ฑ์„ ๋ณด์žฅํ•œ๋‹ค. ๋ฐ˜๋ฉด, ์ปดํฌ๋„ŒํŠธ ๊ฐ„ UI๊ฐ€ ์•„๋‹Œ ๊ธฐ๋Šฅ์„ ์žฌ์‚ฌ์šฉํ•˜๋ ค๋ฉด, ๋ณ„๋„์˜ JavaScript ๋ชจ๋“ˆ๋กœ ๊ตฌ๋ถ„ํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค. ์ดํ›„ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ฐ€์ ธ์™€ ํ™•์žฅํ•˜์ง€ ์•Š๊ณ  ํ•จ์ˆ˜, ๊ฐœ์ฒด, ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

โฌ† Back to Top

  1. react ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์›น ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‚˜?

    react ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์›น ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ๋งŽ์€ ๊ฐœ๋ฐœ์ž๊ฐ€ ์ด ์กฐํ•ฉ์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋”๋ผ๋„ ์›น ์ปดํฌ๋„ŒํŠธ๋กœ ๋งŒ๋“ค์–ด์ง„ ๋‹ค๋ฅธ UI ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ํŠนํžˆ ํ•„์š”ํ•  ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด Vaadin ๋‚ ์งœ ์„ ํƒ๊ธฐ ์›น ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ๋ณด์ž.

    import React, { Component } from 'react';
    import './App.css';
    import '@vaadin/vaadin-date-picker';
    class App extends Component {
      render() {
        return (
          <div className="App">
            <vaadin-date-picker label="When were you born?"></vaadin-date-picker>
          </div>
        );
      }
    }
    export default App;

โฌ† Back to Top

  1. dynamic import๋ž€?

    dynamic import() ๋ฌธ๋ฒ•์€ ํ˜„์žฌ ํ‘œ์ค€ ๋ฌธ๋ฒ•์ด ์•„๋‹Œ ECMAScript ์ œ์•ˆ์ด๋‹ค. ๊ฐ€๊นŒ์šด ๋ฏธ๋ž˜์— ์ถ”๊ฐ€๋  ๊ฒƒ์ด๋‹ค(์‹ค์ œ๋กœ 2020์— ์ถ”๊ฐ€ ์˜ˆ์ •). dynamic import()๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ code-splitting ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋ง์…ˆ ์˜ˆ๋ฅผ ๋“ค์–ด๋ณด์ž.

    1. Normal Import
    import { add } from './math';
    console.log(add(10, 20));
    1. Dynamic Import
    import("./math").then(math => {
      console.log(math.add(10, 20));
    });

โฌ† Back to Top

  1. loadable ์ปดํฌ๋„ŒํŠธ๋ž€?

    ์„œ๋ฒ„ ๋ Œ๋”๋ง ์•ฑ์—์„œ code-splitting์„ ํ•˜๋Š” ๊ฒฝ์šฐ, React.lazy์™€ Suspense๋ฅผ ์•„์ง ์„œ๋ฒ„ ์ธก ๋ Œ๋”๋ง์— ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์œผ๋ฏ€๋กœ Loadable ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค. Loadable์„ ์‚ฌ์šฉํ•˜๋ฉด dynamic import๋ฅผ ์ผ๋ฐ˜ ์ปดํฌ๋„ŒํŠธ๋กœ ๋ Œ๋”๋งํ•  ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด๋ณด๋ฉด,

    import loadable from '@loadable/component'
    
    const OtherComponent = loadable(() => import('./OtherComponent'))
    
    function MyComponent() {
      return (
        <div>
          <OtherComponent />
        </div>
      )
    }

    ์ด์ œ OtherComponent๋Š” ๋ณ„๋„์˜ ๋ฒˆ๋“ค๋กœ ๋กœ๋“œ๋œ๋‹ค.

โฌ† Back to Top

  1. suspense ์ปดํฌ๋„ŒํŠธ๋ž€?

    dynamic import๊ฐ€ ํฌํ•จ๋œ ๋ชจ๋“ˆ์˜ ๋ถ€๋ชจ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ Œ๋”๋ง ๋  ๋•Œ๊นŒ์ง€ ๋กœ๋“œ๊ฐ€ ๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ ๋กœ๋”ฉ ํ‘œ์‹œ๊ธฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋กœ๋“œ๋  ๋•Œ๊นŒ์ง€ ๋Œ€์ฒด ์ปจํ…์ธ ๋ฅผ ํ‘œ์‹œํ•œ๋‹ค. ์ด๋ฅผ Suspense ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ์•„๋ž˜ ์ฝ”๋“œ๋Š” suspense ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

    const OtherComponent = React.lazy(() => import('./OtherComponent'));
    
    function MyComponent() {
      return (
        <div>
          <Suspense fallback={<div>Loading...</div>}>
            <OtherComponent />
          </Suspense>
        </div>
      );
    }

    ์œ„ ์ฝ”๋“œ์—์„œ ์–ธ๊ธ‰ํ–ˆ๋“ฏ์ด Suspense๋Š” Layzy ์ปดํฌ๋„ŒํŠธ๋กœ ๊ฐ์‹ธ์ง„๋‹ค.

โฌ† Back to Top

  1. ๋ผ์šฐํŠธ ๊ธฐ๋ฐ˜์˜ ์ฝ”๋“œ ์Šคํ”Œ๋ฆฌํŒ…์ด๋ž€?

    ์ฝ”๋“œ ์Šคํ”Œ๋ฆฌํŒ…์„ ์‚ฌ์šฉํ•ด ๋ณผ ์ข‹์€ ์žฅ์†Œ ์ค‘ ํ•˜๋‚˜๋Š” ๋ผ์šฐํŠธ๋‹ค. ์ „์ฒด ํŽ˜์ด์ง€๊ฐ€ ํ•œ ๋ฒˆ์— ๋ Œ๋”๋ง ๋˜๋ฏ€๋กœ ์‚ฌ์šฉ์ž๊ฐ€ ํŽ˜์ด์ง€์˜ ๋‹ค๋ฅธ ์š”์†Œ์™€ ๋™์‹œ์— ์ƒํ˜ธ ์ž‘์šฉํ•  ๊ฐ€๋Šฅ์„ฑ์ด ์—†๋‹ค. ์ด๋กœ ์ธํ•ด ์‚ฌ์šฉ์ž ๊ฒฝํ—˜์ด ๋ฐฉํ•ด๋ฐ›์ง€ ์•Š๋Š”๋‹ค. React.lazy์™€ ํ•จ๊ป˜ Reat Router ๊ฐ™์€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฒฝ๋กœ ๊ธฐ๋ฐ˜ ์›น ์‚ฌ์ดํŠธ๋ฅผ ์˜ˆ๋ฅผ ๋“ค์–ด๋ณด์ž.

    import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
    import React, { Suspense, lazy } from 'react';
    
    const Home = lazy(() => import('./routes/Home'));
    const About = lazy(() => import('./routes/About'));
    
    const App = () => (
      <Router>
        <Suspense fallback={<div>Loading...</div>}>
          <Switch>
            <Route exact path="/" component={Home}/>
            <Route path="/about" component={About}/>
          </Switch>
        </Suspense>
      </Router>
    );

    ์œ„์˜ ์ฝ”๋“œ์—์„œ, ์ฝ”๋“œ ์Šคํ”Œ๋ฆฌํŒ…์€ ๊ฐ ๊ฒฝ๋กœ ์ˆ˜์ค€์—์„œ ๋ฐœ์ƒํ•œ๋‹ค.

โฌ† Back to Top

  1. context๋ฅผ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋Š”์ง€์— ๋Œ€ํ•œ ์˜ˆ์ œ

    Context๋Š” React ์ปดํฌ๋„ŒํŠธ ํŠธ๋ฆฌ์—์„œ global๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๊ณต์œ ํ•˜๋„๋ก ์„ค๊ณ„๋˜์—ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์•„๋ž˜ ์ฝ”๋“œ์—์„œ Button ์ปดํฌ๋„ŒํŠธ์˜ ์Šคํƒ€์ผ์„ ์ง€์ •ํ•˜๊ธฐ ์œ„ํ•ด "ํ…Œ๋งˆ" prop์„ ์ˆ˜๋™์œผ๋กœ ์—ฐ๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค.

    //Lets create a context with a default theme value "luna"
    const ThemeContext = React.createContext('luna');
    // Create App component where it uses provider to pass theme value in the tree
    class App extends React.Component {
      render() {
        return (
          <ThemeContext.Provider value="nova">
            <Toolbar />
          </ThemeContext.Provider>
        );
      }
    }
    // A middle component where you don't need to pass theme prop anymore
    function Toolbar(props) {
      return (
        <div>
          <ThemedButton />
        </div>
      );
    }
    // Lets read theme value in the button component to use
    class ThemedButton extends React.Component {
      static contextType = ThemeContext;
      render() {
        return <Button theme={this.context} />;
      }
    }

โฌ† Back to Top

  1. context์—์„œ ๊ธฐ๋ณธ๊ฐ’์˜ ๋ชฉ์ ์€?

    defaultValue ์ธ์ˆ˜๋Š” ์ปดํฌ๋„ŒํŠธ์— ํŠธ๋ฆฌ์—์„œ ์ผ์น˜ํ•˜๋Š” Provider๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ์— ์‚ฌ์šฉ๋œ๋‹ค. ์ด๋Š” ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ฐ์‹ธ์ง€ ์•Š๊ณ  ๋ถ„๋ฆฌํ•˜์—ฌ ํ…Œ์ŠคํŠธํ•˜๋Š”๋ฐ ๋„์›€์ด ๋  ์ˆ˜ ์žˆ๋‹ค. ์•„๋ž˜ ์ฝ”๋“œ๋Š” ํ…Œ๋งˆ ๊ธฐ๋ณธ๊ฐ’์„ Luna๋กœ ์ œ๊ณตํ•œ๋‹ค.

    const MyContext = React.createContext(defaultValue);

โฌ† Back to Top

  1. contextType์€ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋‚˜?

    ContextType์€ context ๊ฐ์ฒด๋ฅผ ์†Œ๋น„ํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋œ๋‹ค. contextType ์†์„ฑ์€ 2๊ฐ€์ง€ ๋ฐฉ์‹์œผ๋กœ ์‚ฌ์šฉ๋œ๋‹ค.

    1. ํด๋ž˜์Šค ์†์„ฑ์œผ๋กœ contextType: ํด๋ž˜์Šค์˜ contextType ์†์„ฑ์—๋Š” React.createContext()๋กœ ๋งŒ๋“  Context ๊ฐ์ฒด๋ฅผ ํ• ๋‹นํ•  ์ˆ˜ ์žˆ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ๋ชจ๋“  ๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฉ”์„œ๋“œ์™€ ๋ Œ๋”๋ง ํ•จ์ˆ˜์—์„œ this.context๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ•ด๋‹น contextType์˜ ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ํ˜„์žฌ ๊ฐ’์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ์•„๋ž˜์™€ ๊ฐ™์ด MyClass์— contextType ์†์„ฑ์„ ํ• ๋‹น ํ•  ์ˆ˜ ์žˆ๋‹ค.
    class MyClass extends React.Component {
      componentDidMount() {
        let value = this.context;
        /* perform a side-effect at mount using the value of MyContext */
      }
      componentDidUpdate() {
        let value = this.context;
        /* ... */
      }
      componentWillUnmount() {
        let value = this.context;
        /* ... */
      }
      render() {
        let value = this.context;
        /* render something based on the value of MyContext */
      }
    }
    MyClass.contextType = MyContext;
    1. Static field ์ •์  ํด๋ž˜์Šค ํ•„๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ณต์šฉ ํด๋ž˜์Šค ํ•„๋“œ ๊ตฌ๋ฌธ์„ ์‚ฌ์šฉํ•˜๋Š” contextType์„ ์ดˆ๊ธฐํ™”ํ•  ์ˆ˜ ์žˆ๋‹ค.
    class MyClass extends React.Component {
      static contextType = MyContext;
      render() {
        let value = this.context;
        /* render something based on the value */
      }
    }

โฌ† Back to Top

  1. consumer๋ž€?

    Consumer๋ž€ context ๋ณ€๊ฒฝ์„ ๊ตฌ๋…ํ•˜๋Š” React ์ปดํฌ๋„ŒํŠธ์ด๋‹ค. ํ˜„์žฌ context ๊ฐ’์„ ์ธ์ˆ˜๋กœ ๋ฐ›๊ณ  react node๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ์ž์‹ ํ•จ์ˆ˜๊ฐ€ ํ•„์š”ํ•˜๋‹ค. ํ•จ์ˆ˜์— ์ „๋‹ฌ๋œ value ์ธ์ˆ˜๋Š” ํŠธ๋ฆฌ์—์„œ context์—์„œ ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด Provider์˜ prop ๊ฐ’๊ณผ ๋™์ผํ•˜๋‹ค. ๊ฐ„๋‹จํ•œ ์˜ˆ๋ฅผ ๋ณด์ž.

    <MyContext.Consumer>
      {value => /* render something based on the context value */}
    </MyContext.Consumer>

โฌ† Back to Top

  1. context๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋™์•ˆ ์„ฑ๋Šฅ ๋ฌธ์ œ๋Š” ์–ด๋–ป๊ฒŒ ํ•ด๊ฒฐํ•˜๋‚˜?

    context๋Š” ๋ฆฌ๋ Œ๋”๋งํ•  ์‹œ๊ธฐ๋ฅผ ๊ฒฐ์ •ํ•  ๋•Œ ์ฐธ์กฐ ID๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. provider์˜ ๋ถ€๋ชจ๊ฐ€ ๋ฆฌ๋ Œ๋”๋ง ๋  ๋•Œ consumer์—์„œ ์˜๋„ํ•˜์ง€ ์•Š์€ ๋ Œ๋”๋ง์„ ์ผ์œผํ‚ฌ ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์•„๋ž˜ ์ฝ”๋“œ๋Š” ์ƒˆ๋กœ์šด ๊ฐ์ฒด๊ฐ€ ํ•ญ์ƒ ๋งŒ๋“ค์–ด์ง€๋ฏ€๋กœ provider๊ฐ€ ๋ฆฌ๋ Œ๋”๋ง ๋  ๋•Œ๋งˆ๋‹ค ๋ชจ๋“  consumer๋ฅผ ๋ Œ๋”๋งํ•œ๋‹ค.

    class App extends React.Component {
      render() {
        return (
          <Provider value={{something: 'something'}}>
            <Toolbar />
          </Provider>
        );
      }
    }

    ์ด๋Š” ๊ฐ’์„ ์ƒ์œ„ state๋กœ ์˜ฌ๋ฆฌ๋ฉด ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค.

    class App extends React.Component {
      constructor(props) {
        super(props);
        this.state = {
          value: {something: 'something'},
        };
      }
    
      render() {
        return (
          <Provider value={this.state.value}>
            <Toolbar />
          </Provider>
        );
      }
    }

โฌ† Back to Top

  1. HOC์—์„œ forward ref์˜ ๋ชฉ์ ์€?

    Refs๋Š” prop์ด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์— ๋„˜๊ธฐ์งˆ ๋ชปํ•œ๋‹ค. key์™€ ๋น„์Šทํ•˜๊ฒŒ React์—์„œ๋Š” ๋‹ค๋ฅด๊ฒŒ ์ฒ˜๋ฆฌํ–ˆ๋‹ค. HOC์— ref๋ฅผ ์ถ”๊ฐ€ํ•˜๋ฉด ํ•ด๋‹น ref๋Š” ๊ฐ์‹ธ์ง„ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์•„๋‹Œ ๊ฐ€์žฅ ๋ฐ”๊นฅ์ชฝ ์ปจํ…Œ์ด๋„ˆ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ฐธ์กฐํ•œ๋‹ค. ์ด ๊ฒฝ์šฐ, Forward Ref API๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, React.forwardRef API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‚ด๋ถ€ FancyButton ์ปดํฌ๋„ŒํŠธ์— ref๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋‹ค.

    ์•„๋ž˜ HOC๋Š” ๋ชจ๋“  props๋ฅผ ๊ธฐ๋กํ•œ๋‹ค.

    function logProps(Component) {
      class LogProps extends React.Component {
        componentDidUpdate(prevProps) {
          console.log('old props:', prevProps);
          console.log('new props:', this.props);
        }
    
        render() {
          const {forwardedRef, ...rest} = this.props;
    
          // Assign the custom prop "forwardedRef" as a ref
          return <Component ref={forwardedRef} {...rest} />;
        }
      }
    
      return React.forwardRef((props, ref) => {
        return <LogProps {...props} forwardedRef={ref} />;
      });
    }

    ์ด HOC๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ โ€œfancy buttonโ€ ์ปดํฌ๋„ŒํŠธ์— ์ „๋‹ฌ๋˜๋Š” ๋ชจ๋“  props๋ฅผ ๊ธฐ๋กํ•ด๋ณด์ž.

    class FancyButton extends React.Component {
      focus() {
        // ...
      }
    
      // ...
    }
    export default logProps(FancyButton);

    ์ด์ œ ref๋ฅผ ๋งŒ๋“ค์–ด FancyButton ์ปดํฌ๋„ŒํŠธ์— ์ „๋‹ฌํ•˜๊ณ  ์žˆ๋‹ค. ์ด ๊ฒฝ์šฐ, ๋ฒ„ํŠผ ์—˜๋ฆฌ๋จผํŠธ์— ํฌ์ปค์Šค๋ฅผ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

    import FancyButton from './FancyButton';
    
    const ref = React.createRef();
    ref.current.focus();
    <FancyButton
      label="Click Me"
      handleClick={handleClick}
      ref={ref}
    />;

โฌ† Back to Top

  1. ref๋Š” ๋ชจ๋“  ํ•จ์ˆ˜ ๋˜๋Š” ํด๋ž˜์Šค ์ปดํฌ๋„ŒํŠธ์—์„œ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•œ๊ฐ€?

    ์ผ๋ฐ˜์ ์ธ ํ•จ์ˆ˜ ๋˜๋Š” ํด๋ž˜์Šค ์ปดํฌ๋„ŒํŠธ๋Š” ref ์ธ์ˆ˜๋กœ ๋ฐ›์ง€ ์•Š์œผ๋ฉฐ, ref๋Š” props์—์„œ๋„ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค. ๋‘ ๋ฒˆ์งธ ref ์ธ์ˆ˜๋Š” React.forwardRef ํ˜ธ์ถœ๋กœ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ •์˜ํ•  ๋•Œ๋งŒ ์กด์žฌํ•œ๋‹ค.

โฌ† Back to Top

  1. forward ref๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋™์•ˆ ์ปดํฌ๋„ŒํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ถ”๊ฐ€๋กœ ๊ด€๋ฆฌํ•ด์•ผํ•˜๋Š” ์ด์œ ๋Š”?

    ์ปดํฌ๋„ŒํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ forwardRef๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์‹œ์ž‘ํ•˜๋ฉด, ์ฃผ์š” ๋ณ€๊ฒฝ์‚ฌํ•ญ์œผ๋กœ ์ทจ๊ธ‰ํ•˜๊ณ  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ์ƒˆ ์ฃผ์š” ๋ฒ„์ „์„ ๋ฆด๋ฆฌ์ฆˆ ํ•ด์•ผ ํ•œ๋‹ค. ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์— ref๊ฐ€ ์ง€์ •๋˜๊ณ  ๋‚ด๋ณด๋‚ด๋Š” ์œ ํ˜•๊ณผ ๊ฐ™์€ ๋‹ค๋ฅธ ๋™์ž‘์ด ์žˆ์„ ์ˆ˜ ์žˆ๋‹ค. ์ด๋Ÿฌํ•œ ๋ณ€๊ฒฝ์œผ๋กœ ์ธํ•ด ์ด์ „ ๋™์ž‘์— ์˜์กดํ•˜๋Š” ์•ฑ ๋ฐ ๊ธฐํƒ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์†์ƒ๋  ์ˆ˜ ์žˆ๋‹ค.

โฌ† Back to Top

  1. ES6 ์—†์ด react ํด๋ž˜์Šค ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์€?

    ES6๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๋Œ€์‹  create-react-class ๋ชจ๋“ˆ์„ ์‚ฌ์šฉํ•ด์•ผ ํ•  ์ˆ˜ ์žˆ๋‹ค. ๊ธฐ๋ณธ props์˜ ๊ฒฝ์šฐ, ์ „๋‹ฌ๋œ ๊ฐ์ฒด์˜ ํ•จ์ˆ˜๋กœ getDefaultProps()๋ฅผ ์ •์˜ํ•ด์•ผ ํ•œ๋‹ค. ์ดˆ๊ธฐ state์ธ ๊ฒฝ์šฐ, ์ดˆ๊ธฐ state๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ณ„๋„์˜ getInitialState ๋ฉ”์„œ๋“œ๋ฅผ ์ œ๊ณตํ•ด์•ผ ํ•œ๋‹ค.

    var Greeting = createReactClass({
      getDefaultProps: function() {
          return {
            name: 'Jhohn'
          };
        },
      getInitialState: function() {
          return {message: this.props.message};
        },
      handleClick: function() {
         console.log(this.state.message);
      },
      render: function() {
        return <h1>Hello, {this.props.name}</h1>;
      }
    });

    Note: createReactClass๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ชจ๋“  ๋ฉ”์„œ๋“œ์— ์ž๋™ ๋ฐ”์ธ๋”ฉ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ์ฆ‰, ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ์˜ ์ƒ์„ฑ์ž์— .bind(this)๋ฅผ ์‚ฌ์šฉํ•  ํ•„์š”๊ฐ€ ์—†๋‹ค.

โฌ† Back to Top

  1. react์—์„œ JSX ์—†์ด ๊ฐ€๋Šฅํ•œ๊ฐ€?

    ๋„ค, JSX๋Š” React๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐ ํ•„์ˆ˜๊ฐ€ ์•„๋‹ˆ๋‹ค. ์‹ค์ œ๋กœ ๋นŒ๋“œ ํ™˜๊ฒฝ์—์„œ ์ปดํŒŒ์ผ์„ ์„ค์ •ํ•˜์ง€ ์•Š์„ ๋•Œ ํŽธ๋ฆฌํ•˜๋‹ค. ๊ฐ JSX ์š”์†Œ๋Š” React.createElement(component, props, ...children)๋ฅผ ํ˜ธ์ถœํ•˜๊ธฐ ์œ„ํ•œ syntactic sugar์ด๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด JSX๋กœ ์ธ์‚ฌ(Greeting)๋ฅผ ๋งŒ๋“ค์–ด ๋ณด์ž.

    class Greeting extends React.Component {
      render() {
        return <div>Hello {this.props.message}</div>;
      }
    }
    
    ReactDOM.render(
      <Greeting message="World" />,
      document.getElementById('root')
    );

    ์•„๋ž˜์™€ ๊ฐ™์ด JSX ์—†์ด ๋™์ผํ•œ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

    class Greeting extends React.Component {
      render() {
        return React.createElement('div', null, `Hello ${this.props.message}`);
      }
    }
    
    ReactDOM.render(
      React.createElement(Greeting, {message: 'World'}, null),
      document.getElementById('root')
    );

โฌ† Back to Top

  1. diffing ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด๋ž€?

    React๋Š” ์ตœ์‹  ํŠธ๋ฆฌ์™€ ์ผ์น˜ํ•˜๋„๋ก UI๋ฅผ ํšจ์œจ์ ์œผ๋กœ ์—…๋ฐ์ดํŠธํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ฐพ๊ธฐ ์œ„ํ•ด์„œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ•œ๋‹ค. diffing ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด๋ž€ ํ•˜๋‚˜์˜ ํŠธ๋ฆฌ๋ฅผ ๋‹ค๋ฅธ ํŠธ๋ฆฌ๋กœ ๋ณ€ํ™˜ํ•˜๊ธฐ ์œ„ํ•ด ์ตœ์†Œํ•œ์˜ ์ˆ˜ ์—ฐ์‚ฐ์„ ํ•œ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜, ์ด ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ O(n3)์˜ ๋ณต์žก์„ฑ์„ ๊ฐ€์ง€๋ฉฐ, ์—ฌ๊ธฐ์„œ n์€ ํŠธ๋ฆฌ์˜ element์˜ ์ˆ˜์ด๋‹ค. ์ด ๊ฒฝ์šฐ, 1000๊ฐœ์˜ element๋ฅผ ํ‘œ์‹œํ•˜๋ ค๋ฉด 10์–ต ๊ฐœ์˜ ๋น„๊ต ์ˆœ์„œ๊ฐ€ ํ•„์š”ํ•˜๋‹ค. ์ด๊ฒƒ์€ ๋„ˆ๋ฌด ๋น„์‹ธ๋‹ค. ๋Œ€์‹  React๋Š” ๋‹ค์Œ ๋‘ ๊ฐ€์ง€ ๊ฐ€์ •์„ ๊ธฐ๋ฐ˜์œผ๋กœ ํœด๋ฆฌ์Šคํ‹ฑ O(n) ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๊ตฌํ˜„ํ•œ๋‹ค.

    1. ๋‹ค๋ฅธ ์œ ํ˜•์˜ ๋‘ element๋Š” ๋‹ค๋ฅธ ํŠธ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•  ๊ฒƒ์ด๋‹ค.
    2. ๊ฐœ๋ฐœ์ž๋Š” key prop๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค๋ฅธ ๋ Œ๋”๋ง์—์„œ ์–ด๋–ค ํ•˜์œ„ element๊ฐ€ ๋ณ€๊ฒฝ๋˜์ง€ ์•Š๋Š”์ง€ ์•”์‹œํ•œ๋‹ค.

โฌ† Back to Top

  1. diffing ์•Œ๊ณ ๋ฆฌ์ฆ˜์— ์ ์šฉ๋˜๋Š” ๊ทœ์น™์€?

    ์„œ๋กœ ๋‹ค๋ฅธ ํŠธ๋ฆฌ๋ฅผ ๋น„๊ตํ•  ๋•Œ, React๋Š” ๋จผ์ € ๋‘ ๊ฐœ์˜ root element๋ฅผ ๋น„๊ตํ•œ๋‹ค. root element์˜ ํƒ€์ž…์— ๋”ฐ๋ผ ๋™์ž‘์ด ๋‹ค๋ฅด๋‹ค. reconciliation ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ค‘ ์•„๋ž˜์˜ ๊ทœ์น™์„ ๋”ฐ๋ฅธ๋‹ค.

    1. ๋‹ค๋ฅธ ํƒ€์ž…์˜ Elements root element๊ฐ€ ๋‹ค๋ฅธ ํƒ€์ž…์„ ๊ฐ€์งˆ ๋•Œ๋งˆ๋‹ค React๋Š” ์ด์ „ ํŠธ๋ฆฌ๋ฅผ ๋ถ„ํ•ดํ•˜๊ณ  ์ฒ˜์Œ๋ถ€ํ„ฐ ์ƒˆ๋กœ์šด ํŠธ๋ฆฌ๋ฅผ ๋งŒ๋“ ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, elements <a>๋Š” <img>๋กœ, ๋˜๋Š” <Article>์—์„œ <Comment>๋กœ ๋‹ค๋ฅธ ํƒ€์ž…์˜ element๋Š” ์ „์ฒด๋ฅผ ๋‹ค์‹œ ์ž‘์„ฑํ•œ๋‹ค.
    2. ๋™์ผํ•œ ํƒ€์ž…์˜ DOM Elements ๋™์ผํ•œ ํƒ€์ž…์˜ ๋‘ React DOM element๋ฅผ ๋น„๊ตํ•  ๋•Œ React๋Š” ๋‘ ์†์„ฑ์„ ๋ชจ๋‘ ๋ณด๊ณ  ๋™์ผํ•œ ๊ธฐ๋ณธ DOM ๋…ธ๋“œ๋ฅผ ์œ ์ง€ํ•˜๋ฉฐ ๋ณ€๊ฒฝ๋œ ์†์„ฑ๋งŒ ์—…๋ฐ์ดํŠธํ•œ๋‹ค. className ์†์„ฑ์„ ์ œ์™ธํ•œ ์†์„ฑ์ด ๋™์ผํ•œ DOM element๋กœ ์˜ˆ์ œ๋ฅผ ๋ณด์ž.
      <div className="show" title="ReactJS" />
      
      <div className="hide" title="ReactJS" />
    3. ๋™์ผํ•œ ํƒ€์ž…์˜ ์ปดํฌ๋„ŒํŠธ Elements ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์—…๋ฐ์ดํŠธ ๋˜๋ฉด, ์ธ์Šคํ„ด์Šค๋Š” ๋™์ผํ•˜๊ฒŒ ์œ ์ง€๋˜๋ฏ€๋กœ ๋ Œ๋”๋ง์—์„œ state๋Š” ์œ ์ง€๋œ๋‹ค. React๋Š” ํ•˜์œ„ element ์ธ์Šคํ„ด์Šค์˜ prop์„ ์ƒˆ element์™€ ์ผ์น˜ํ•˜๋„๋ก ์—…๋ฐ์ดํŠธํ•˜๊ณ  ํ•˜์œ„ ์ธ์Šคํ„ด์Šค์—์„œ componentWillReceiveProps()์™€ componentWillUpdate()๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ, render() ๋ฉ”์„œ๋“œ๊ฐ€ ํ˜ธ์ถœ๋˜๊ณ  ์ด์ „ ๊ฒฐ๊ณผ์™€ ์ƒˆ ๊ฒฐ๊ณผ์—์„œ ์žฌ๊ท€์ ์œผ๋กœ diff ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์ด๋ฃจ์–ด์ง„๋‹ค.
    4. Children ์žฌ๊ท€ DOM ๋…ธ๋“œ์˜ ์ž์‹์— ๋Œ€ํ•ด ์žฌ๊ท€๊ฐ€ ์ด๋ฃจ์–ด์งˆ ๋•Œ, React๋Š” ๋‘ ๊ฐœ์˜ ์ž์‹ ๋ชฉ๋ก์„ ๋™์‹œ์— ๋ฐ˜๋ณตํ•˜๊ณ  ์ฐจ์ด๊ฐ€ ์žˆ์„ ๋•Œ๋งˆ๋‹ค ๋ณ€์ด๋ฅผ ์ผ์œผํ‚จ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์ž์‹์˜ ๋์— element๋ฅผ ์ถ”๊ฐ€ํ•  ๋•Œ ๋‘ ํŠธ๋ฆฌ๋ฅผ ๋ณ€๊ฒฝ์‹œํ‚ค๋Š” ๊ฒŒ ์œ ๋ฆฌํ•˜๋‹ค.
      <ul>
        <li>first</li>
        <li>second</li>
      </ul>
      
      <ul>
        <li>first</li>
        <li>second</li>
        <li>third</li>
      </ul>
    5. keys ํ•ธ๋“ค๋ง React๋Š” key ์†์„ฑ์„ ์ง€์›ํ•œ๋‹ค. ์ž์‹์— ํ‚ค๊ฐ€ ์žˆ์œผ๋ฉด, React๋Š” ์ด ํ‚ค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์›๋ž˜ ํŠธ๋ฆฌ์˜ ์ž์‹์„ ๋‹ค์Œ ํŠธ๋ฆฌ์˜ ์ž์‹๊ณผ ์ผ์น˜์‹œํ‚จ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, key๋ฅผ ์ถ”๊ฐ€ํ•˜๋ฉด ํŠธ๋ฆฌ ๋ณ€ํ™˜์ด ํšจ์œจ์ ์ด๋‹ค.
    <ul>
      <li key="2015">Duke</li>
      <li key="2016">Villanova</li>
    </ul>
    
    <ul>
      <li key="2014">Connecticut</li>
      <li key="2015">Duke</li>
      <li key="2016">Villanova</li>
    </ul>

โฌ† Back to Top

  1. ์–ธ์ œ ref๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋‚˜?

    ref ์‚ฌ์šฉ ์ผ€์ด์Šค๋Š” ๊ฑฐ์˜ ์—†๋‹ค.

    1. ์ดˆ์ , ํ…์ŠคํŠธ ์„ ํƒ, ๋ฏธ๋””์–ด ์žฌ์ƒ ๊ด€๋ฆฌ
    2. ๋ช…๋ นํ˜• ์• ๋‹ˆ๋ฉ”์ด์…˜ ํŠธ๋ฆฌ๊ฑฐ
    3. ํƒ€์‚ฌ DOM ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€ ํ†ตํ•ฉ

โฌ† Back to Top

  1. prop์„ render prop์˜ ๋ Œ๋”๋ง์œผ๋กœ ์ง€์ •ํ•ด์•ผ ํ•˜๋‚˜?

    render props๋ผ ๋ถˆ๋ฆฌ๋Š” ํŒจํ„ด์ด ์žˆ์–ด๋„, ์ด ํŒจํ„ด์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด render๋ผ ๋ถˆ๋ฆฌ๋Š” prop์„ ์‚ฌ์šฉํ•  ํ•„์š”๋Š” ์—†๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์ฆ‰, ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ Œ๋”๋ง ๋Œ€์ƒ์„ ์•Œ๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋˜๋Š” ๊ธฐ๋Šฅ์ธ ๋ชจ๋“  prop์€ ๊ธฐ์ˆ ์ ์œผ๋กœ โ€œrender propโ€์ด๋‹ค. render props์— ๋Œ€ํ•ด ์ž์‹ prop์„ ์˜ˆ๋ฅผ ๋“ค์–ด๋ณด์ž.
    <Mouse children={mouse => (
      <p>The mouse position is {mouse.x}, {mouse.y}</p>
    )}/>
    ์‹ค์ œ๋กœ ์ž์‹ prop์€ JSX element์˜ โ€œ์†์„ฑโ€ ๋ชฉ๋ก์— ์ด๋ฆ„์„ ์ง€์ •ํ•  ํ•„์š”๊ฐ€ ์—†๋‹ค. ๋Œ€์‹ ์—, element ๋‚ด๋ถ€์— ์ง์ ‘ ์œ ์ง€ํ•  ์ˆ˜ ์žˆ๋‹ค.
    <Mouse>
      {mouse => (
        <p>The mouse position is {mouse.x}, {mouse.y}</p>
      )}
    </Mouse>
    ์œ„์˜ ๊ธฐ์ˆ ์„ ์‚ฌ์šฉํ•˜๋Š” ๋™์•ˆ(์ด๋ฆ„ ์—†์ด), ์ž์‹์€ propTypes์˜ ํ•จ์ˆ˜์—ฌ์•ผ ํ•œ๋‹ค๊ณ  ๋ช…์‹œ์ ์œผ๋กœ ์ž‘์„ฑํ•ด์•ผ ํ•œ๋‹ค.
    Mouse.propTypes = {
      children: PropTypes.func.isRequired
    };

โฌ† Back to Top

  1. ์ˆœ์ˆ˜ ์ปดํฌ๋„ŒํŠธ์™€ render props๋ฅผ ๊ฐ™์ด ์‚ฌ์šฉํ•˜๋ฉด ๋ฌธ์ œ๊ฐ€ ์žˆ๋‚˜?

    render ๋ฉ”์„œ๋“œ ์•ˆ์—์„œ ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒฝ์šฐ, ์ˆœ์ˆ˜ ์ปดํฌ๋„ŒํŠธ์˜ ๋ชฉ์ ์— ๋งž์ง€ ์•Š๋Š”๋‹ค. ์–•์€ prop ๋น„๊ต๋Š” ํ•ญ์ƒ ์ƒˆ๋กœ์šด props์— ๋Œ€ํ•ด false๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋ฉฐ ๊ฐ ๋ Œ๋”๋ง์€ ๋ Œ๋”๋ง prop์— ๋Œ€ํ•ด ์ƒˆ๋กœ์šด ๊ฐ’์„ ์ƒ์„ฑํ•œ๋‹ค. ๋ Œ๋”๋ง ํ•จ์ˆ˜๋ฅผ ์ธ์Šคํ„ด์Šค ๋ฉ”์„œ๋“œ๋กœ ์ •์˜ํ•˜์—ฌ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค.

โฌ† Back to Top

  1. ์–ด๋–ป๊ฒŒ render props๋ฅผ ์‚ฌ์šฉํ•ด์„œ HOC๋ฅผ ๋งŒ๋“œ๋‚˜?

    render prop๊ณผ ์ผ๋ฐ˜์ ์ธ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•ด์„œ higher-order components (HOC)๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, <Mouse> ์ปดํฌ๋„ŒํŠธ ๋Œ€์‹  withMouse HOC๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด render prop๊ณผ ํ•จ๊ป˜ <Mouse>๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‰ฝ๊ฒŒ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค.

    function withMouse(Component) {
      return class extends React.Component {
        render() {
          return (
            <Mouse render={mouse => (
              <Component {...this.props} mouse={mouse} />
            )}/>
          );
        }
      }
    }

    ์ด ๋ฐฉ๋ฒ•์œผ๋กœ render prop๋Š” ๋‘ ํŒจํ„ด ์ค‘ ํ•˜๋‚˜๋ฅผ ์‚ฌ์šฉํ•˜๋„๋ก ํ•ด์ค€๋‹ค.

โฌ† Back to Top

  1. windowing technique์ด๋ž€?

    Windowing์€ ์ฃผ์–ด์ง„ ์‹œ๊ฐ„์— ํ–‰์˜ ์ž‘์€ ๋ถ€๋ถ„ ์ง‘ํ•ฉ๋งŒ ๋ Œ๋”๋งํ•˜๋Š” ๊ธฐ์ˆ ๋กœ, ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋‹ค์‹œ ๋ Œ๋”๋งํ•˜๋Š” ๋ฐ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„๊ณผ ์ƒ์„ฑ๋œ DOM ๋…ธ๋“œ์˜ ์ˆ˜๋ฅผ ํฌ๊ฒŒ ์ค„์ผ ์ˆ˜ ์žˆ๋‹ค. ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ๊ธด ๋ฐ์ดํ„ฐ ๋ชฉ๋ก์„ ๋ Œ๋”๋งํ•˜๋Š” ๊ฒฝ์šฐ ์ด ๊ธฐ์ˆ ์ด ๊ถŒ์žฅ๋œ๋‹ค. react-window์™€ react-virtualized๋Š” ๋ชจ๋‘ ๋ชฉ๋ก, ๊ทธ๋ฆฌ๋“œ ๋ฐ ํ…Œ์ด๋ธ” ํ˜•์‹ ๋ฐ์ดํ„ฐ๋ฅผ ํ‘œ์‹œํ•˜๊ธฐ ์œ„ํ•ด ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์—ฌ๋Ÿฌ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ œ๊ณตํ•˜๋Š” windowing ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๋‹ค.

โฌ† Back to Top

  1. JSX์—์„œ ์ž˜๋ชป๋œ ๊ฐ’์€ ์–ด๋–ป๊ฒŒ ์ถœ๋ ฅํ•˜๋‚˜?

    false, null, undefined ๋ฐ true ๊ฐ™์€ ํ—ˆ์œ„๊ฐ’์€ ์œ ํšจํ•œ ์ž์‹์ด์ง€๋งŒ, ์•„๋ฌด๊ฒƒ๋„ ๋ Œ๋”๋งํ•˜์ง€ ์•Š๋Š”๋‹ค. ํ‘œ์‹œํ•˜๋ ค๋ฉด ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜ํ•ด์•ผ ํ•œ๋‹ค. ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ์˜ˆ์ œ๋ฅผ ๋ณด์ž.

    <div>
      My JavaScript variable is {String(myVariable)}.
    </div>

โฌ† Back to Top

  1. portals๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์‚ฌ๋ก€๋Š”?

    React portals๋Š” ์ƒ์œ„ ์ปดํฌ๋„ŒํŠธ๊ฐ€ overflow: hidden์ด๊ฑฐ๋‚˜ stacking context(z- ์ƒ‰์ธ, ์œ„์น˜, ๋ถˆํˆฌ๋ช…๋„ ๋“ฑ ์Šคํƒ€์ผ)์— ์˜ํ–ฅ์„ ์ฃผ๋Š” ํŠน์„ฑ์— ์˜ํ–ฅ์„ ์ค€๋‹ค๋ฉด, ์ปจํ…Œ์ด๋„ˆ์—์„œ ์‹œ๊ฐ์ ์œผ๋กœ "๋ถ„๋ฆฌ"ํ•˜๋Š”๋ฐ ๋„์›€์„ ์ค€๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, dialogs, global message notifications, hovercards, ํˆดํŒ์ด ์žˆ๋‹ค.

โฌ† Back to Top

  1. ์ œ์–ด๋˜์ง€ ์•Š๋Š” ์ปดํฌ๋„ŒํŠธ์˜ ๊ธฐ๋ณธ๊ฐ’์„ ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    React์—์„œ, form ์š”์†Œ์—์„œ value ์†์„ฑ์€ DOM์˜ ๊ฐ’์„ ๋Œ€์ฒดํ•œ๋‹ค. ์ œ์–ด๋˜์ง€ ์•Š๋Š” ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด React๊ฐ€ ์ดˆ๊ธฐ๊ฐ’์„ ์ง€์ •ํ•˜์ง€๋งŒ, ์—…๋ฐ์ดํŠธ๋Š” ์ œ์–ด๋˜์ง€ ์•Š๋Š” ์ƒํƒœ๋กœ ๋‘๊ฒŒ ๋œ๋‹ค. ์ด ๊ฒฝ์šฐ๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด value ๋Œ€์‹  defaultValue ์†์„ฑ์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

    render() {
      return (
        <form onSubmit={this.handleSubmit}>
          <label>
            User Name:
            <input
              defaultValue="John"
              type="text"
              ref={this.input} />
          </label>
          <input type="submit" value="Submit" />
        </form>
      );
    }

    select๊ณผ textArea ์ž…๋ ฅ์—๋„ ๋™์ผํ•˜๊ฒŒ ์ ์šฉ๋œ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ checkbox ๋ฐ radio ์ž…๋ ฅ์—๋Š” defaultChecked ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค.

โฌ† Back to Top

  1. ๊ฐ€์žฅ ์ข‹์•„ํ•˜๋Š” React stack์€?

    ๊ธฐ์ˆ  ์Šคํƒ์€ ๊ฐœ๋ฐœ์ž๋งˆ๋‹ค ๋‹ค๋ฅด์ง€๋งŒ ๊ฐ€์žฅ ์ธ๊ธฐ ์žˆ๋Š” ์Šคํƒ์€ react ๋ณด์ผ๋Ÿฌ ํ”Œ๋ ˆ์ดํŠธ ํ”„๋กœ์ ํŠธ ์ฝ”๋“œ์— ์‚ฌ์šฉ๋œ๋‹ค. ์ฃผ๋กœ ์ƒํƒœ ๊ด€๋ฆฌ ๋ฐ ๋น„๋™๊ธฐ ๋ถ€์ž‘์šฉ์„ ์œ„ํ•ด Redux ๋ฐ redux-saga, ๋ผ์šฐํŒ… ๋ชฉ์ ์„ ์œ„ํ•œ react-router, react ์ปดํฌ๋„ŒํŠธ๋ฅผ ์Šคํƒ€์ผ๋งํ•˜๊ธฐ ์œ„ํ•œ styled-component, REST api๋ฅผ ํ˜ธ์ถœํ•˜๊ธฐ ์œ„ํ•œ axios, ๊ทธ๋ฆฌ๊ณ  ๋‹ค๋ฅธ ์Šคํƒ๋“ค๋กœ๋Š” webpack, reselect, ESNext, Babel์ด ์žˆ๋‹ค. https://github.com/react-boilerplate/react-boilerplate๋ฅผ clone ๋ฐ›์•„์„œ ์ƒˆ๋กœ์šด react ํ”„๋กœ์ ํŠธ ์ž‘์—…์„ ์‹œ์ž‘ํ•  ์ˆ˜ ์žˆ๋‹ค.

โฌ† Back to Top

  1. Real DOM๊ณผ Virtual DOM์˜ ์ฐจ์ด์ ์€?

    ์•„๋ž˜์— Real DOM๊ณผ Virtual DOM์˜ ์ฃผ์š” ์ฐจ์ด์ ์„ ์‚ดํŽด๋ณด์ž,

    Real DOM Virtual DOM
    ์—…๋ฐ์ดํŠธ๊ฐ€ ๋Š๋ฆฌ๋‹ค ์—…๋ฐ์ดํŠธ๊ฐ€ ๋น ๋ฅด๋‹ค
    DOM ์กฐ์ž‘์ด ์ €๋ ดํ•˜๋‹ค DOM ์กฐ์ž‘์ด ๋งค์šฐ ์‰ฝ๋‹ค.
    HTML์„ ์ง์ ‘ ์—…๋ฐ์ดํŠธํ•œ๋‹ค. HTML์„ ์ง์ ‘ ์—…๋ฐ์ดํŠธ ํ•  ์ˆ˜ ์—†๋‹ค.
    ๋„ˆ๋ฌด ๋งŽ์€ ๋ฉ”๋ชจ๋ฆฌ ๋‚ญ๋น„๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค. ๋ฉ”๋ชจ๋ฆฌ ๋‚ญ๋น„๊ฐ€ ์—†๋‹ค.
    element๊ฐ€ ์—…๋ฐ์ดํŠธ ๋˜๋ฉด ์ƒˆ DOM์„ ๋งŒ๋“ ๋‹ค. element๊ฐ€ ์—…๋ฐ์ดํŠธ ๋˜๋ฉด JSX๋ฅผ ์—…๋ฐ์ดํŠธํ•œ๋‹ค.

โฌ† Back to Top

  1. react ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋ถ€ํŠธ์ŠคํŠธ๋žฉ์„ ์ถ”๊ฐ€ํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    ๋ถ€ํŠธ์ŠคํŠธ๋žฉ์€ ์„ธ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์œผ๋กœ React ์•ฑ์— ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋‹ค.

    1. ๋ถ€ํŠธ์ŠคํŠธ๋žฉ CDN ์‚ฌ์šฉ: ๋ถ€ํŠธ์ŠคํŠธ๋žฉ์„ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฐ€์žฅ ์‰ฌ์šด ๋ฐฉ๋ฒ•์ด๋‹ค. ๋ถ€ํŠธ์ŠคํŠธ๋žฉ CSS ๋ฐ JS ์ž์›์„ ํ—ค๋“œ ํƒœ๊ทธ์— ์ถ”๊ฐ€ํ•œ๋‹ค.

    2. ๋ถ€ํŠธ์ŠคํŠธ๋žฉ Dependency ์ถ”๊ฐ€ํ•˜๊ธฐ: ๋นŒ๋“œ ๋„๊ตฌ๋‚˜ Webpack๊ณผ ๊ฐ™์€ ๋ชจ๋“ˆ ๋ฒˆ๋“ค๋Ÿฌ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ React ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋ถ€ํŠธ์ŠคํŠธ๋žฉ์„ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒŒ ์ข‹๋‹ค.

      npm install bootstrap
      ``
    3. React ๋ถ€ํŠธ์ŠคํŠธ๋žฉ ํŒจํ‚ค์ง€ : ์ด ๊ฒฝ์šฐ, ๋ถ€ํŠธ์ŠคํŠธ๋žฉ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์žฌ๋นŒ๋“œํ•œ ํŒจํ‚ค์ง€๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํŠนํžˆ React ์ปดํฌ๋„ŒํŠธ๋กœ ์ž‘๋™ํ•˜๋Š” React ์•ฑ์— ๋ถ€ํŠธ์ŠคํŠธ๋žฉ์„ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋‹ค. ์•„๋ž˜ ํŒจํ‚ค์ง€๋Š” ์ธ๊ธฐ์žˆ๋Š” ํŒจํ‚ค์ง€ ์ค‘ ํ•˜๋‚˜์ด๋‹ค.

      1. react-bootstrap
      2. reactstrap

โฌ† Back to Top

  1. ํ”„๋ก ํŠธ์—”๋“œ ํ”„๋ ˆ์ž„์›Œํฌ๋กœ React๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฉ”์ธ ์›น์‚ฌ์ดํŠธ๋‚˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€?

    ์•„๋ž˜๋Š” React๋ฅผ ํ”„๋ก ํŠธ์—”๋“œ ํ”„๋ ˆ์ž„์›Œํฌ๋กœ ์‚ฌ์šฉํ•˜๋Š” top 10 websites์ด๋‹ค.

    1. Facebook
    2. Uber
    3. Instagram
    4. WhatsApp
    5. Khan Academy
    6. Airbnb
    7. Dropbox
    8. Flipboard
    9. Netflix
    10. PayPal

โฌ† Back to Top

  1. React์—์„œ CSS In JS ๊ธฐ์ˆ ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ ์ข‹์€๊ฐ€?

    React๋Š” ์Šคํƒ€์ผ์„ ์–ด๋–ป๊ฒŒ ํ•˜๋ผ๋Š” ์ •์˜๊ฐ€ ์—†์–ด์„œ, ์ดˆ๋ณด์ž๋ผ๋ฉด ์Šคํƒ€์ผ์„ ํ‰์†Œ์™€ ๊ฐ™์ด ๋ณ„๋„์˜ *.css ํŒŒ์ผ์— ์ •์˜ํ•˜๊ณ  className์„ ์‚ฌ์šฉํ•˜์—ฌ ์ฐธ์กฐํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค. CSS In JS ๊ธฐ๋Šฅ์€ React์˜ ์ผ๋ถ€๋Š” ์•„๋‹ˆ์ง€๋งŒ ํƒ€์‚ฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ๋‹ค๋ฅธ ์ ‘๊ทผ๋ฒ•(CSS-In-JS)์„ ์‹œ๋„ํ•˜๋ ค๋ฉด ์Šคํƒ€์ผ ์ปดํฌ๋„ŒํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์ข‹์€ ๋ฐฉ์•ˆ์ด๋‹ค.

โฌ† Back to Top

  1. ๋ชจ๋“  ํด๋ž˜์Šค ์ปดํฌ๋„ŒํŠธ๋ฅผ hook์œผ๋กœ ์ „ํ™˜ํ•ด์•ผํ•˜๋‚˜?

    ์•„๋‹ˆ์š”. ๊ทธ๋Ÿฌ๋‚˜ ๊ธฐ์กด ์ฝ”๋“œ๋ฅผ ๋‹ค์‹œ ์ž‘์„ฑํ•˜์ง€ ์•Š๊ณ ๋„ ์ผ๋ถ€ ์ปดํฌ๋„ŒํŠธ(๋˜๋Š” ์ƒˆ๋กœ์šด ์ปดํฌ๋„ŒํŠธ)์—์„œ hook์„ ์‹œ๋„ํ•  ์ˆ˜ ์žˆ๋‹ค. ReactJS์—์„œ ํด๋ž˜์Šค๋ฅผ ์ œ๊ฑฐํ•  ๊ณ„ํš์ด ์—†๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

โฌ† Back to Top

  1. React hook์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ๋ฐฉ๋ฒ•์€?

    useEffect๋ผ๋Š” effect hook์€ API์—์„œ axios๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๊ณ  state hook์˜ ์—…๋ฐ์ดํŠธ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ปดํฌ๋„ŒํŠธ์˜ ๋กœ์ปฌ ์ƒํƒœ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์„ค์ •ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋œ๋‹ค. API๋กœ ๊ธฐ์‚ฌ ๋ชฉ๋ก์„ ๊ฐ€์ ธ์˜ค๋Š” ์˜ˆ๋ฅผ ๋“ค์–ด๋ณด์ž.

    import React, { useState, useEffect } from 'react';
    import axios from 'axios';
    
    function App() {
      const [data, setData] = useState({ hits: [] });
    
      useEffect(async () => {
        const result = await axios(
          'http://hn.algolia.com/api/v1/search?query=react',
        );
    
        setData(result.data);
      }, []);
    
      return (
        <ul>
          {data.hits.map(item => (
            <li key={item.objectID}>
              <a href={item.url}>{item.title}</a>
            </li>
          ))}
        </ul>
      );
    }
    
    export default App;

    ์ปดํฌ๋„ŒํŠธ ์—…๋ฐ์ดํŠธ ์‹œ ์ž‘๋™ํ•˜์ง€ ์•Š๊ณ  ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋งˆ์šดํŠธํ•  ๋•Œ๋งŒ ์ž‘๋™ํ•˜๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด effect hook์— ๋‘ ๋ฒˆ์งธ ์ธ์ˆ˜๋กœ ๋นˆ ๋ฐฐ์—ด์„ ์ œ๊ณตํ•œ๋‹ค. ์ฆ‰ ์ปดํฌ๋„ŒํŠธ ๋งˆ์šดํŠธ์— ๋Œ€ํ•ด์„œ๋งŒ ๊ฐ€์ ธ์˜จ๋‹ค.

โฌ† Back to Top

  1. Hook์€ ํด๋ž˜์Šค์˜ ๋ชจ๋“  ์‚ฌ์šฉ ์‚ฌ๋ก€๋ฅผ ์ปค๋ฒ„ํ•  ์ˆ˜ ์žˆ๋‚˜?

    Hook์€ ํด๋ž˜์Šค์˜ ๋ชจ๋“  ์‚ฌ์šฉ ์‚ฌ๋ก€๋ฅผ ๋‹ค๋ฃจ์ง€๋Š” ๋ชปํ•˜์ง€๋งŒ, ๊ณง ์ถ”๊ฐ€ํ•  ๊ณ„ํš์ด ์žˆ๋‹ค. ํ˜„์žฌ๋Š” ์ผ๋ฐ˜์ ์ด์ง€ ์•Š์€ getSnapshotBeforeUpdate์™€ componentDidCatch ๋ผ์ดํ”„ ์‚ฌ์ดํด์— ํ•ด๋‹นํ•˜๋Š” Hook์ด ์—†๋‹ค.

โฌ† Back to Top

  1. hook ์ง€์›์„ ์œ„ํ•œ ์•ˆ์ •์ ์ธ ๋ฆด๋ฆฌ์ฆˆ๋Š”?

    React๋Š” 16.8 ๋ฆด๋ฆฌ์ฆˆ์˜ ์•ˆ์ •์ ์ธ ํŒจํ‚ค์ง€๋กœ ์•„๋ž˜ ํŒจํ‚ค์ง€๋ฅผ ์•ˆ์ •์ ์œผ๋กœ ๊ตฌํ˜„ํ•˜์˜€๋‹ค.

    1. React DOM
    2. React DOM Server
    3. React Test Renderer
    4. React Shallow Renderer

โฌ† Back to Top

  1. useState์—์„œ๋Š” ์™œ destructuring(๋Œ€๊ด„ํ˜ธ ํ‘œ๊ธฐ๋ฒ•)์„ ์‚ฌ์šฉํ•˜๋‚˜?

    useState๋กœ state ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๋ฉด ๋‘ ํ•ญ๋ชฉ์ด ์žˆ๋Š” ๋ฐฐ์—ด์ธ ์Œ์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ์ฒซ ๋ฒˆ์งธ ํ•ญ๋ชฉ์€ ํ˜„์žฌ ๊ฐ’์ด๊ณ , ๋‘ ๋ฒˆ์งธ ํ•ญ๋ชฉ์€ ๊ฐ’์„ ์—…๋ฐ์ดํŠธํ•˜๋Š” ํ•จ์ˆ˜์ด๋‹ค. [0]๊ณผ [1]์„ ์‚ฌ์šฉํ•˜์—ฌ ์•ก์„ธ์Šคํ•˜๋Š” ๊ฒƒ์€ ํŠน์ •ํ•œ ์˜๋ฏธ๋ฅผ ๊ฐ€์ง€๊ธฐ ๋•Œ๋ฌธ์— ์•ฝ๊ฐ„ ํ˜ผ๋™๋œ๋‹ค. ์šฐ๋ฆฌ๊ฐ€ ๋Œ€์‹  destructuring์„ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ์ด๋‹ค.

    ์˜ˆ๋ฅผ ๋“ค์–ด, ๋ฐฐ์—ด ์ธ๋ฑ์Šค ์•ก์„ธ์Šค๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

     var userStateVariable = useState('userProfile'); // Returns an array pair
     var user = userStateVariable[0]; // Access first item
     var setUser = userStateVariable[1]; // Access second item

    ๋ฐฐ์—ด destructuring์„ ์‚ฌ์šฉํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์•ก์„ธ์Šคํ•  ์ˆ˜ ์žˆ๋‹ค.

    const [user, setUser] = useState('userProfile');

    โฌ† Back to Top

  2. hook์„ ๋„์ž…ํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋˜๋Š” ์†Œ์Šค๋Š”?

    Hooks๋Š” ์—ฌ๋Ÿฌ ๋‹ค๋ฅธ ์ถœ์ฒ˜์—์„œ ์•„์ด๋””์–ด๋ฅผ ์–ป์—ˆ๋‹ค. ์•„๋ž˜๋Š” ๊ทธ์ค‘ ์ผ๋ถ€์ด๋‹ค.

    1. react-future repository์—์„œ ํ•จ์ˆ˜ํ˜• API๋ฅผ ์‚ฌ์šฉํ•œ ์ด์ „์˜ ์‹คํ—˜.
    2. Reactions Component์™€ ๊ฐ™์€ ๋ Œ๋”๋ง propAPI๋ฅผ ์‚ฌ์šฉํ•œ ์ปค๋ฎค๋‹ˆํ‹ฐ ์‹คํ—˜.
    3. DisplayScript์˜ state ๋ณ€์ˆ˜ ๋ฐ state ์…€.
    4. Rx์˜ ๊ตฌ๋….
    5. ReasonReact์˜ Reducer ์ปดํฌ๋„ŒํŠธ.

โฌ† Back to Top

  1. ์›น ์ปดํฌ๋„ŒํŠธ์˜ ๋ช…๋ นํ˜• API์— ์ ‘๊ทผํ•˜๋Š” ๋ฐฉ๋ฒ•์€?

    Web ์ปดํฌ๋„ŒํŠธ๋Š” ์ข…์ข… ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•ด ๋ช…๋ นํ˜• API๋ฅผ ๋…ธ์ถœํ•œ๋‹ค. ์›น ์ปดํฌ๋„ŒํŠธ์˜ ๋ช…๋ นํ˜• API์— ์•ก์„ธ์Šคํ•˜๋ ค๋ฉด ref๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ DOM ๋…ธ๋“œ์™€ ์ง์ ‘ ์ƒํ˜ธ ์ž‘์šฉํ•ด์•ผ ํ•œ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ํƒ€์‚ฌ ์›น ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ๊ฐ€์žฅ ์ข‹์€ ํ•ด๊ฒฐ์ฑ…์€ ์›น ์ปดํฌ๋„ŒํŠธ์˜ wrapper๋กœ ๋™์ž‘ํ•˜๋Š” React ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ž‘์„ฑํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

โฌ† Back to Top

  1. formik์ด๋ž€?

    Formik๋Š” ์„ธ ๊ฐ€์ง€ ์ฃผ์š” ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋Š” ๋ฐ ๋„์›€์ด ๋˜๋Š” ์ž‘์€ react ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๋‹ค.

    1. form state์˜ ๊ฐ’ ๊ฐ€์ ธ์˜ค๊ธฐ
    2. ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ์™€ ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€
    3. form ์ œ์ถœ ์ฒ˜๋ฆฌ

โฌ† Back to Top

  1. Redux์—์„œ ๋น„๋™๊ธฐ ํ˜ธ์ถœ์„ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ์ผ๋ฐ˜์ ์ธ ๋ฏธ๋“ค์›จ์–ด๋Š”?

    Redux eco system์—์„œ ๋น„๋™๊ธฐ์‹ ํ˜ธ์ถœ์„ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด ๋งŽ์ด ์‚ฌ์šฉ๋˜๋Š” ๋ฏธ๋“ค์›จ์–ด๋Š” Redux Thunk, Redux Promise, Redux Saga์ด๋‹ค.

โฌ† Back to Top

  1. ๋ธŒ๋ผ์šฐ์ €๊ฐ€ JSX ์ฝ”๋“œ๋ฅผ ์ดํ•ดํ•˜๋‚˜?

    ์•„๋‹ˆ์š”, ๋ธŒ๋ผ์šฐ์ €๋Š” JSX ์ฝ”๋“œ๋ฅผ ์ดํ•ดํ•  ์ˆ˜ ์—†๋‹ค. ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋Š” JSX๋ฅผ ์ผ๋ฐ˜ Javascript๋กœ ๋ณ€ํ™˜ํ•˜๋ ค๋ฉด ํŠธ๋žœ์ŠคํŒŒ์ผ๋Ÿฌ๊ฐ€ ํ•„์š”ํ•˜๋‹ค. ํ˜„์žฌ ๊ฐ€์žฅ ๋„๋ฆฌ ์‚ฌ์šฉ๋˜๋Š” ํŠธ๋žœ์ŠคํŒŒ์ผ๋Ÿฌ๋Š” Babel์ด๋‹ค.

โฌ† Back to Top

  1. React์—์„œ ๋ฐ์ดํ„ฐ ํ๋ฆ„์— ๋Œ€ํ•ด ์„ค๋ช…ํ•˜์ž๋ฉด?

    React๋Š” ๋ณด์ผ๋Ÿฌ ํ”Œ๋ ˆ์ดํŠธ๋ฅผ ์ค„์ด๊ณ  ๊ธฐ์กด์˜ ์–‘๋ฐฉํ–ฅ ๋ฐ์ดํ„ฐ ๋ฐ”์ธ๋”ฉ๋ณด๋‹ค ์ดํ•ดํ•˜๊ธฐ ์‰ฝ๋„๋ก props๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‹จ๋ฐฉํ–ฅ ๋ฐ˜์‘์„ฑ ๋ฐ์ดํ„ฐ ํ๋ฆ„์„ ๊ตฌํ˜„ํ•˜์˜€๋‹ค.

โฌ† Back to Top

  1. react scripts๋ž€?

    react-scripts ํŒจํ‚ค์ง€๋Š” create-react-app starter pack์˜ ์„ธํŠธ๋กœ ๋ณ„๋„์˜ ์„ค์ •์„ ํ•˜์ง€ ์•Š๊ณ  ํ”„๋กœ์ ํŠธ๋ฅผ ์‹œ์ž‘ํ•  ์ˆ˜ ์žˆ๋‹ค. react-scripts start ๋ช…๋ น์–ด๋Š” ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์„ ์„ค์ •ํ•˜๊ณ  ์„œ๋ฒ„์™€ ํ•ซ ๋ชจ๋“ˆ ๋ฆฌ๋กœ๋”ฉ์„ ์‹œ์ž‘ํ•œ๋‹ค.

โฌ† Back to Top

  1. create react app์˜ ๊ธฐ๋Šฅ์€?

    ์•„๋ž˜๋Š” create react app์—์„œ ์ œ๊ณตํ•˜๋Š” ์ผ๋ถ€ ๊ธฐ๋Šฅ ๋ชฉ๋ก์ด๋‹ค.

    1. React, JSX, ES6, Typescript์™€ Flow syntax ์ง€์›.
    2. Autoprefixed CSS
    3. CSS Reset/Normalize
    4. ๋ผ์ด๋ธŒ ๊ฐœ๋ฐœ ์„œ๋ฒ„
    5. ์ปค๋ฒ„๋ฆฌ์ง€ ๋ฆฌํฌํŒ…์„ ์ง€์›ํ•˜๋Š” ๋น ๋ฅธ interactive unit ํ…Œ์ŠคํŠธ runner ๋‚ด์žฅ
    6. hashes์™€ sourcemaps๋ฅผ ํฌํ•จํ•œ production์„ ์œ„ํ•œ JS, CSS, ์ด๋ฏธ์ง€ ๋ฒˆ๋“ค ๋นŒ๋“œ ์Šคํฌ๋ฆฝํŠธ ์ œ๊ณต
    7. ๋ชจ๋“  Progressive Web App ๊ธฐ์ค€์„ ์ถฉ์กฑํ•˜๋Š” ์˜คํ”„๋ผ์ธ ์šฐ์„  ์„œ๋น„์Šค ์›Œ์ปค์™€ ์›น ์•ฑ manifest

โฌ† Back to Top

  1. renderToNodeStream ๋ฉ”์„œ๋“œ์˜ ๋ชฉ์ ์€?

    ReactDOMServer#renderToNodeStream ๋ฉ”์„œ๋“œ๋Š” ์„œ๋ฒ„์—์„œ ์ดˆ๊ธฐ ์š”์ฒญ์— ๋” ๋น ๋ฅธ ํŽ˜์ด์ง€ ๋กœ๋“œ๋ฅผ ์œ„ํ•ด HTML์„ ์ƒ์„ฑํ•˜๋Š” ๋ฐ ์‚ฌ์šฉํ•œ๋‹ค. ๋˜ํ•œ, ๊ฒ€์ƒ‰์—”์ง„์ด SEO ๋ชฉ์ ์œผ๋กœ ํŽ˜์ด์ง€๋ฅผ ์‰ฝ๊ฒŒ ํฌ๋กค๋งํ•˜๋Š” ๋ฐ ๋„์›€์„ ์ค€๋‹ค. ์ฐธ๊ณ  : ์ด ๋ฐฉ๋ฒ•์€ ๋ธŒ๋ผ์šฐ์ €์—์„œ๋Š” ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์œผ๋ฉฐ ์„œ๋ฒ„์—์„œ๋งŒ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค.

โฌ† Back to Top

  1. MobX๋ž€?

    MobX๋Š” functional reactive programming (TFRP)์„ ์ ์šฉํ•˜๊ธฐ ์œ„ํ•œ ๋‹จ์ˆœํ•˜๋ฉฐ ํ™•์žฅ์„ฑ์ด ์ข‹๊ณ  battle tested ์ƒํƒœ ๊ด€๋ฆฌ ์†”๋ฃจ์…˜์ด๋‹ค. reactJs ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๊ฒฝ์šฐ, ์•„๋ž˜ ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•ด์•ผ ํ•œ๋‹ค.

    npm install mobx --save
    npm install mobx-react --save

โฌ† Back to Top

  1. Redux์™€ MobX์˜ ์ฐจ์ด์ ์€?

    ๋‹ค์Œ์€ Redux์™€ MobX์˜ ์ฃผ์š” ์ฐจ์ด์ ์ด๋‹ค.

    Topic Redux MobX
    ์ •์˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ƒํƒœ๋ฅผ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ƒํƒœ๋ฅผ ๋ฐ˜์‘์ ์œผ๋กœ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
    ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ฃผ๋กœ ES6 ์ฃผ๋กœ JavaScript(ES5)
    ๋ฐ์ดํ„ฐ ์ €์žฅ ๋ฐ์ดํ„ฐ ์ €์žฅ์„ ์œ„ํ•œ ํ•˜๋‚˜์˜ ํฐ ์ €์žฅ์†Œ๊ฐ€ ์กด์žฌ ์ €์žฅ์„ ์œ„ํ•œ ๋‘ ๊ฐœ ์ด์ƒ์˜ ์Šคํ† ์–ด๊ฐ€ ์กด์žฌ
    ์‚ฌ์šฉ์„ฑ ์ฃผ๋กœ ํฌ๊ณ  ๋ณต์žกํ•œ ์‘์šฉ ๋ถ„์•ผ์— ์‚ฌ์šฉ ๋‹จ์ˆœํ•œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์‚ฌ์šฉ
    ์„ฑ๋Šฅ ๊ฐœ์„ ์ด ํ•„์š” ๋” ๋‚˜์€ ์„ฑ๋Šฅ ์ œ๊ณต
    ์ €์žฅ๋ฐฉ์‹ JS Object๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ €์žฅ observable๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ ์ €์žฅ

โฌ† Back to Top

  1. ReactJS๋ฅผ ๋ฐฐ์šฐ๊ธฐ ์ „์— ES6๋ฅผ ๋ฐฐ์›Œ์•ผ ํ•˜๋‚˜?

    ์•„๋‹ˆ์š”, react๋ฅผ ๋ฐฐ์šฐ๊ธฐ ์œ„ํ•ด์„œ es2015/es6๋ฅผ ๋ฐฐ์šธ ํ•„์š”๋Š” ์—†๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ๋งŽ์€ ๋ฆฌ์†Œ์Šค์™€ React ์ƒํƒœ๊ณ„์—์„œ ES6๋ฅผ ๊ด‘๋ฒ”์œ„ํ•˜๊ฒŒ ์‚ฌ์šฉํ•œ๋‹ค. ์ž์ฃผ ์‚ฌ์šฉ๋˜๋Š” ES6 ๊ธฐ๋Šฅ ์ค‘ ์ผ๋ถ€๋ฅผ ๋ณด๋„๋ก ํ•˜์ž.

    1. Destructuring: props๋ฅผ ๊ฐ€์ ธ์™€์„œ ์ปดํฌ๋„ŒํŠธ์—์„œ ์‚ฌ์šฉํ•œ๋‹ค.
    // in es 5
     var someData = this.props.someData
     var dispatch = this.props.dispatch
    
    // in es6
    const { someData, dispatch } = this.props
    1. Spread operator: props๋ฅผ ์ปดํฌ๋„ŒํŠธ์— ์ „๋‹ฌํ•˜๋Š”๋ฐ ๋„์›€์ด ๋œ๋‹ค.
    // in es 5
    <SomeComponent someData={this.props.someData} dispatch={this.props.dispatch} />
    
    // in es6
    <SomeComponent {...this.props} />
    1. Arrow functions: ๊ฐ„๊ฒฐํ•œ ๊ตฌ๋ฌธ์„ ๋งŒ๋“ค์–ด ์ค€๋‹ค.
    // es 5
    var users = usersList.map(function (user) {
     return <li>{user.name}</li>
    })
    // es 6
    const users = usersList.map(user => <li>{user.name}</li>);

โฌ† Back to Top

  1. Concurrent Rendering์ด๋ž€?

    Concurrent rendering์€ ๊ธฐ๋ณธ UI ์Šค๋ ˆ๋“œ๋ฅผ ์ฐจ๋‹จํ•˜์ง€ ์•Š๊ณ  ์ปดํฌ๋„ŒํŠธ ํŠธ๋ฆฌ๋ฅผ ๋ Œ๋”๋งํ•˜์—ฌ React ์•ฑ์˜ ์‘๋‹ต์„ฑ์„ ํ–ฅ์ƒํ•œ๋‹ค. React๊ฐ€ ์šฐ์„ ์ˆœ์œ„๊ฐ€ ๋†’์€ ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด ์žฅ์‹œ๊ฐ„ ๊ฑธ๋ฆฌ๋Š” ๋ Œ๋”๋ง์„ ์ค‘๋‹จํ•  ์ˆ˜ ์žˆ๋‹ค. ์ฆ‰, ๋™์‹œ ๋ชจ๋“œ๋ฅผ ํ™œ์„ฑํ™” ํ™”๋ฉด React๋Š” ์ˆ˜ํ–‰ํ•ด์•ผ ํ•˜๋Š” ๋‹ค๋ฅธ ์ž‘์—…์„ ์ฃผ์‹œํ•˜๊ณ  ์šฐ์„ ์ˆœ์œ„๊ฐ€ ๋†’์€ ๊ฒƒ์ด ์žˆ์œผ๋ฉด ํ˜„์žฌ ๋ Œ๋”๋ง ์ค‘์ธ ๊ฒƒ์„ ์ผ์‹œ ์ค‘์ง€ํ•˜๊ณ  ๋‹ค๋ฅธ ์ž‘์—…์„ ๋จผ์ € ์™„๋ฃŒํ•œ๋‹ค. ์ด๋ฅผ ๋‘ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์œผ๋กœ ํ™œ์„ฑํ™” ํ•  ์ˆ˜ ์žˆ๋‹ค.

    // 1. Part of an app by wrapping with ConcurrentMode
    <React.unstable_ConcurrentMode>
      <Something />
    </React.unstable_ConcurrentMode>
    
    // 2. Whole app using createRoot
    ReactDOM.unstable_createRoot(domNode).render(<App />);

โฌ† Back to Top

  1. async ๋ชจ๋“œ์™€ concurrent ๋ชจ๋“œ์˜ ์ฐจ์ด์ ์€?

    ๋‘˜ ๋‹ค ๊ฐ™์€ ๊ฒƒ์„ ๋œปํ•œ๋‹ค. ์ด์ „์— ๋™์‹œ ๋ชจ๋“œ๋Š” React ํŒ€์—์„œ "๋น„๋™๊ธฐ ๋ชจ๋“œ"๋ผ๊ณ  ํ–ˆ๋‹ค. ์ด๋ฆ„์ด ๋‹ค๋ฅธ ์šฐ์„ ์ˆœ์œ„ ์ˆ˜์ค€์—์„œ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋Š” React์˜ ๊ธฐ๋Šฅ์„ ๊ฐ•์กฐํ•˜๋„๋ก ๋ณ€๊ฒฝ๋˜์—ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๋น„๋™๊ธฐ ๋ Œ๋”๋ง์— ๋Œ€ํ•œ ๋‹ค๋ฅธ ์ ‘๊ทผ ๋ฐฉ์‹์˜ ํ˜ผ๋™์„ ํ”ผํ–ˆ๋‹ค.

โฌ† Back to Top

  1. react16.9์—์„œ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ urls๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‚˜?

    ๋„ค, javascript: URL์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, ์ฝ˜์†”์— ๊ฒฝ๊ณ ๋ฅผ ๊ธฐ๋กํ•œ๋‹ค. javascript: ๋กœ ์‹œ์ž‘ํ•˜๋Š” URL์€ <a href>์™€ ๊ฐ™์€ ํƒœ๊ทธ์— ์ข‹์ง€ ์•Š์€ ์ถœ๋ ฅ์„ ํฌํ•จํ•˜์—ฌ ๋ณด์•ˆ ํ—ˆ์ ์„ ๋งŒ๋“ค์–ด ์œ„ํ—˜ํ•˜๋‹ค.

    const companyProfile = {
      website: "javascript: alert('Your website is hacked')",
    };
    // It will log a warning
    <a href={companyProfile.website}>More details</a>

    ํ–ฅํ›„ ๋ฒ„์ „์—์„œ๋Š” ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ URL ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•  ๊ฒƒ์ด๋‹ค.

โฌ† Back to Top

  1. hooks์—์„œ eslint ํ”Œ๋Ÿฌ๊ทธ์ธ์˜ ๋ชฉ์ ์€?

    ESLint ํ”Œ๋Ÿฌ๊ทธ์ธ์€ ๋ฒ„๊ทธ๋ฅผ ํ”ผํ•˜๊ณ ์ž Hooks์˜ ๊ทœ์น™์„ ๊ฐ•์กฐํ•œ๋‹ค. ๋ชจ๋“  ํ•จ์ˆ˜ โ€useโ€๋กœ ์‹œ์ž‘ํ•˜๋ฉฐ Hook ๋ฐ”๋กœ ๋’ค์— ๋Œ€๋ฌธ์ž๊ฐ€ ์žˆ์–ด์•ผ ํ•œ๋‹ค.

    1. Hooks์˜ ํ˜ธ์ถœ์€ PascalCase ํ•จ์ˆ˜ ๋‚ด(์ปดํฌ๋„ŒํŠธ๋กœ ๊ฐ€์ •) ๋˜๋Š” ๋‹ค๋ฅธ useSomething ํ•จ์ˆ˜(์ปค์Šคํ…€ Hook์œผ๋กœ ๊ฐ€์ •) ๋‚ด์— ์žˆ๋‹ค.
    2. Hooks๋Š” ๋ชจ๋“  ๋ Œ๋”๋ง์—์„œ ๋™์ผํ•œ ์ˆœ์„œ๋กœ ํ˜ธ์ถœ๋œ๋‹ค.

โฌ† Back to Top

  1. React์—์„œ ๋ช…๋ นํ˜•๊ณผ ์„ ์–ธํ˜•์˜ ์ฐจ์ด์ ์€?

    "์ข‹์•„์š”" ๋ฒ„ํŠผ๊ณผ ๊ฐ™์€ ๊ฐ„๋‹จํ•œ UI ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ƒ์ƒํ•ด๋ณด์ž. ํƒญ ํ•˜๋ฉด ์ด์ „์— ํšŒ์ƒ‰์ด๋˜ ๊ฒƒ์ด ํŒŒ๋ž€์ƒ‰์œผ๋กœ ๋ฐ”๋€Œ๊ณ  ํŒŒ๋ž€์ƒ‰์ด์—ˆ์œผ๋ฉด ํšŒ์ƒ‰์œผ๋กœ ๋ฐ”๋€๋‹ค.

    ์ด๋ฅผ ์ˆ˜ํ–‰ํ•˜๋Š” ๋ช…๋ น์  ๋ฐฉ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

    if( user.likes() ) {
        if( hasBlue() ) {
            removeBlue();
            addGrey();
        } else {
            removeGrey();
            addBlue();
        }
    }

    ๊ธฐ๋ณธ์ ์œผ๋กœ ํ˜„์žฌ ํ™”๋ฉด์˜ ๋‚ด์šฉ์„ ํ™•์ธํ•˜๊ณ  ์ด์ „ ์ƒํƒœ์—์„œ ๋ณ€๊ฒฝ๋˜๋Š” ๋‚ด์šฉ์„ ์‹คํ–‰ ์ทจ์†Œํ•˜๋Š” ๋“ฑ ํ˜„์žฌ ์ƒํƒœ๋กœ ๋‹ค์‹œ ๊ทธ๋ฆฌ๋Š” ๋ฐ ํ•„์š”ํ•œ ๋ชจ๋“  ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ์ฒ˜๋ฆฌํ•ด์•ผ ํ•œ๋‹ค. ์‹ค์ œ ์‹œ๋‚˜๋ฆฌ์˜ค์—์„œ ์ด๊ฒƒ์ด ์–ผ๋งˆ๋‚˜ ๋ณต์žกํ•œ์ง€ ์ƒ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค.

    ๋ฐ˜๋Œ€๋กœ, ์„ ์–ธ์  ์ ‘๊ทผ ๋ฐฉ์‹์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

    if( this.state.liked ) {
        return <blueLike />;
    } else {
        return <greyLike />;
    }

    ์„ ์–ธ์  ์ ‘๊ทผ ๋ฐฉ์‹์€ ์šฐ๋ ค๋˜๋Š” ์‚ฌํ•ญ์„ ๊ตฌ๋ถ„ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ด ๋ถ€๋ถ„์€ UI๊ฐ€ ๋ณ„๊ฐœ์˜ ์ƒํƒœ๋กœ ํ‘œ์‹œ๋˜๋Š” ๋ฐฉ์‹๋งŒ ์ฒ˜๋ฆฌํ•˜๋ฉด ๋˜๋ฏ€๋กœ ์ดํ•ดํ•˜๊ธฐ ์ข‹๋‹ค.

โฌ† Back to Top

  1. Reactjs์™€ ํ•จ๊ป˜ Typescript๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ์žฅ์ ?

    ๋‹ค์Œ์€ Reactjs์™€ ํ•จ๊ป˜ Typescript๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์–ป์„ ์ˆ˜ ์žˆ๋Š” ์žฅ์ ์˜ ์ผ๋ถ€์ด๋‹ค.

    1. ์ตœ์‹  Javascript ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
    2. ๋ณต์žกํ•œ ํƒ€์ž… ์ •์˜๋ฅผ ์œ„ํ•œ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
    3. VS Code์™€ ๊ฐ™์€ IDE๋Š” Typescript๋ฅผ ์œ„ํ•ด ๋งŒ๋“ค์–ด์กŒ๋‹ค.
    4. ๊ฐ€๋…์„ฑ ๋ฐ ๊ฒ€์ฆ์ด ์šฉ์ดํ•˜์—ฌ ๋ฒ„๊ทธ ๋ฐฉ์ง€๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.
  2. Context API State Management ์‚ฌ์šฉ ์‹œ ํŽ˜์ด์ง€ ์ƒˆ๋กœ ๊ณ ์นจ์„ ํ•ด๋„ ์‚ฌ์šฉ์ž๊ฐ€ ์ธ์ฆ๋œ ์ƒํƒœ๋ฅผ ์œ ์ง€ํ•˜๋Š” ๋ฐฉ๋ฒ•์€??

์‚ฌ์šฉ์ž๊ฐ€ ๋กœ๊ทธ์ธ๋œ ์ƒํƒœ๋กœ ์ƒˆ๋กœ ๊ณ ์นจ ํ•  ๋•Œ, ์ผ๋ฐ˜์ ์œผ๋กœ ์ƒํƒœ๋ฅผ ์œ ์ง€ํ•˜๊ธฐ ์œ„ํ•ด main App.js์˜ useEffect hooks์•ˆ์˜ load user action์„ ์ถ”๊ฐ€ํ•œ๋‹ค. Redux๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋™์•ˆ, loadUser action์— ์‰ฝ๊ฒŒ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋‹ค.

App.js

import { loadUser }  from '../actions/auth';
store.dispatch(loadUser());
  • ๊ทธ๋Ÿฌ๋‚˜ Context API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ App.js์˜ context์— ์•ก์„ธ์Šคํ•˜๋Š” ๋™์•ˆ, App.js๊ฐ€ auth context์— ์•ก์„ธ์Šคํ•  ์ˆ˜ ์žˆ๋„๋ก index.js์—์„œ AuthState๋กœ ๊ฐ์‹ธ์•ผ ํ•œ๋‹ค. ์ด์ œ ํŽ˜์ด์ง€๊ฐ€ ๋‹ค์‹œ ๋กœ๋“œ๋  ๋•Œ๋งˆ๋‹ค ์–ด๋–ค ๊ฒฝ๋กœ์— ์žˆ๋“ , ์‚ฌ์šฉ์ž๋Š” loadUser action์ด ํŠธ๋ฆฌ๊ฑฐ ๋  ๊ฒฝ์šฐ ๊ฐ๊ฐ์ด re-render๋จ์œผ๋กœ์„œ ์ธ์ฆ๋œ๋‹ค.

index.js

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import AuthState from './context/auth/AuthState'

ReactDOM.render(
  <React.StrictMode>
    <AuthState>
      <App />
    </AuthState>
  </React.StrictMode>,
  document.getElementById('root')
);

App.js

const authContext = useContext(AuthContext);

const { loadUser } = authContext;

useEffect(() => {
  loadUser();
},[])

loadUser

const loadUser = async () => {
  const token = sessionStorage.getItem('token');

  if(!token){
    dispatch({
      type: ERROR
    })
  }
  setAuthToken(token);

  try {
    const res = await axios('/api/auth'); 

    dispatch({
      type: USER_LOADED,
      payload: res.data.data
    })
      
  } catch (err) {
    console.error(err); 
  }
}

โฌ† Back to Top

  1. ์ƒˆ๋กœ์šด JSX transform์˜ ์žฅ์ ์€?

3๊ฐ€์ง€์˜ ์ƒˆ๋กœ์šด JSX transform ์ฃผ์š” ์žฅ์ ์ด ์žˆ๋‹ค.

  1. React packages๋ฅผ ๊ฐ€์ ธ์˜ค์ง€ ์•Š๊ณ  JSX๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
  2. ๋” ์ž‘์€ ์‚ฌ์ด์ฆˆ๋กœ ์ปดํŒŒ์ผ ๊ฒฐ๊ณผ๋ฌผ์ด ๋งŒ๋“ค์–ด์ง€๋„๋ก ๊ฐœ์„ ๋˜์—ˆ๋‹ค.
  3. ์ถ”ํ›„ React๋ฅผ ๋ฐฐ์šฐ๋Š”๋ฐ ํ•„์š”ํ•œ ๊ฐœ๋…์„ ์ค„์ผ ์ˆ˜ ์žˆ๋„๋ก ์œ ์—ฐํ•จ์„ ์ œ๊ณตํ•œ๋‹ค.

โฌ† Back to Top

  1. ์ƒˆ๋กœ์šด JSX transform๊ณผ ์˜ˆ์ „ transform์˜ ์ฐจ์ด์ ์€?

์ƒˆ๋กœ์šด JSX transform์€ scope ๋‚ด React๊ฐ€ ํ•„์š” ์—†๋‹ค. ์ฆ‰, ๊ฐ„๋‹จํ•œ ๊ฒฝ์šฐ์—๋Š” React ํŒจํ‚ค์ง€๋ฅผ ๊ฐ€์ ธ์˜ฌ ํ•„์š” ์—†๋‹ค.

์˜ˆ์ „ transform๊ณผ ์ƒˆ๋กœ์šด transform์˜ ์ฃผ์š” ์ฐจ์ด์ ์„ ์‚ดํŽด๋ณด์ž.

Old Transform:

import React from 'react';

function App() {
  return <h1>Good morning!!</h1>;
}

์ด์ œ JSX transform์€ ์•„๋ž˜์™€ ๊ฐ™์ด ์ผ๋ฐ˜์ ์ธ JavaScript๋กœ ๋ณ€ํ™˜ํ•œ๋‹ค.

import React from 'react';

function App() {
  return React.createElement('h1', null, 'Good morning!!');
}

New Transform:

์ƒˆ๋กœ์šด JSX transform์—๋Š” React๊ฐ€ ํ•„์š”ํ•˜์ง€ ์•Š๋‹ค.

function App() {
  return <h1>Good morning!!</h1>;
}

์œ„์˜ ์ฝ”๋“œ๋Š” JSX transform์‹œ ์•„๋ž˜์˜ ์ฝ”๋“œ๋กœ ์ปดํŒŒ์ผ๋œ๋‹ค.

import {jsx as _jsx} from 'react/jsx-runtime';

function App() {
  return _jsx('h1', { children: 'Good morning!!' });
}

Note: Hook์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ์—ฌ์ „ํžˆ React๋ฅผ ๊ฐ€์ ธ์™€์•ผ ํ•œ๋‹ค.

โฌ† Back to Top

  1. ์–ด๋–ป๊ฒŒ create-react-app๋ฅผ ์‚ฌ์šฉํ•ด์„œ redux scaffolding์„ ํ•˜๋‚˜?

Redux ํŒ€์€ create-react-app ํ”„๋กœ์ ํŠธ๋ฅผ ์œ„ํ•ด ๊ณต์‹์œผ๋กœ redux+js, redux+typescript ํƒฌํ”Œ๋ฆฟ์„ ์ œ๊ณตํ•œ๋‹ค. ์ƒ์„ฑ๋œ ํ”„๋กœ์ ํŠธ์—๋Š” ์•„๋ž˜์˜ ํ•ญ๋ชฉ์ด ํฌํ•จ๋œ๋‹ค.

  1. Redux Toolkit๊ณผ React-Redux ์˜์กด์„ฑ.
  2. Redux store ์ƒ์„ฑ ๋ฐ ์„ค์ •.
  3. React-Redux <Provider>๊ฐ€ store๋ฅผ React components์— ์ „๋‹ฌ.
  4. redux logic ๋ฐ React-Redux hooks API๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ components์—์„œ store์™€ ์ƒํ˜ธ ์ž‘์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ณด์—ฌ์ฃผ๋Š” ์ž‘์€ "counter" ์˜ˆ์ œ.

์•„๋ž˜ ๋ช…๋ น์–ด๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ…œํ”Œ๋ฆฟ ์˜ต์…˜๊ณผ ํ•จ๊ป˜ ์‹คํ–‰๋˜์–ด์•ผ ํ•œ๋‹ค.

  1. Javascript template:
npx create-react-app my-app --template redux
  1. Typescript template:
npx create-react-app my-app --template redux-typescript

โฌ† Back to Top

  1. React Server components๋ž€?

React Server Component๋Š” React app ์„ฑ๋Šฅ์„ ํ–ฅ์ƒ ์‹œํ‚ฌ ๋ชฉ์ ์œผ๋กœ server-side์—์„œ ๋ Œ๋”๋ง ๋œ React ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ž‘์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. ์ด๋Ÿฌํ•œ ์ปดํฌ๋„ŒํŠธ๋Š” ๋ฐฑ์—”๋“œ์—์„œ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋กœ๋“œํ•  ์ˆ˜ ์žˆ๋‹ค.

Note: React Server Components๋Š” ์•„์ง ๊ฐœ๋ฐœ ์ค‘์ด๋ฉฐ ์•„์ง ํ”„๋กœ๋•์…˜์— ๊ถŒ์žฅ๋˜์ง€ ์•Š๋Š”๋‹ค.

โฌ† Back to Top

  1. prop drilling ์ด๋ž€ ๋ฌด์—‡์ธ๊ฐ€?

Prop Drilling์€ data๊ฐ€ ํ•„์š”ํ•˜์ง€ ์•Š์ง€๋งŒ, ์˜ค์ง ์ „๋‹ฌํ•˜๋Š” ๋ฐ ๋„์›€์ด ๋˜๋Š” ์ปดํฌ๋„ŒํŠธ๋ฅผ ํ†ตํ•ด React Component tree์˜ component์—์„œ ๋‹ค๋ฅธ component๋กœ data๋ฅผ ์ „๋‹ฌํ•˜๋Š” ํ”„๋กœ์„ธ์Šค์ž…๋‹ˆ๋‹ค.

  1. What are the different ways to prevent state mutation?

โฌ† Back to Top

reactjs-interview-questions-korean's People

Contributors

barrymichaeldoyle avatar bkjang avatar bodycount avatar coreyshirk avatar cygra avatar dhrubesh avatar dididy avatar ibk6 avatar koronya avatar lehasvv2009 avatar mshwed avatar omerg avatar sahajre avatar seonhyungjo avatar sudheerj avatar uronly14me avatar winstonmarvel avatar yashwanth2804 avatar zlldnv avatar zxhycxq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

reactjs-interview-questions-korean's Issues

PR ์ฐธ์—ฌ ๋ฐฉ์‹์— ๋Œ€ํ•œ ๋…ผ์˜

๊ฐœ์ธ์ ์ธ ์ƒ๊ฐ์œผ๋กœ๋Š” react ๊ณต์‹ ๋ฌธ์„œ ๋ฒˆ์—ญ ๋ ˆํฌ์™€ ๊ฐ™์ด ๋ฒˆ์—ญํ•  ๋ถ€๋ถ„์„ ๊ฐœ๊ฐœ์ธ์ด ํ• ๋‹นํ•ด๊ฐ€๋Š” ๋ฐฉ์‹์œผ๋กœ ์ •๋ฆฌ๋ฅผ ํ•˜๋ฉด ์–ด๋–จ๊นŒ์š”?
์˜๊ฒฌ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

[์ถ”๊ฐ€์š”์ฒญ] ๋ฒˆ์—ญ๋ฆฌ์ŠคํŠธ ๋งํฌ ์ถ”๊ฐ€

[์ถ”๊ฐ€์š”์ฒญ] ๋ฒˆ์—ญ๋ฆฌ์ŠคํŠธ ๋งํฌ ์ถ”๊ฐ€

ํ˜„์žฌ ๋ฒˆ์—ญ๋ฆฌ์ŠคํŠธ์—์„œ Translate 6, 7 ๊ด€๋ จํ•˜์—ฌ ๋งํฌ๊ฐ€ ์ž‘๋™์„ ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ถ”๊ฐ€ ์ˆ˜์ • ๋ฐ hotfix ์š”์ฒญ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

330๋ฒˆ ์ œ๋ชฉ ์ถ”๊ฐ€ ๋ฒˆ์—ญ ์š”์ฒญ

330๋ฒˆ ํ•˜๋‹จ ๋ฒˆ์—ญ์€ ์™„๋ฃŒ๊ฐ€ ๋œ ๊ฒƒ์œผ๋กœ ํ™•์ธํ–ˆ์œผ๋‚˜ ์ƒ๋‹จ ๋ฆฌ์ŠคํŠธ์—์„œ ๋ฒˆ์—ญ ์ž‘์—…์ด ๋˜์–ด์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

์ฒ˜๋ฆฌ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

[๊ณต์ง€์‚ฌํ•ญ] Korean Translation Progress

Korean Translation Progress

๋ฒˆ์—ญํ•ด์ฃผ์‹œ๋Š” ๋ถ„

@SeonHyungJo
@BKJang
@dididy

์ƒˆ๋กœ์šด ๋ฒˆ์—ญ๊ฐ€๋ถ„๋“ค์€ ํ™•์ธํ•ด์ฃผ์„ธ์š”!!

ํ˜„์žฌ ์ด์Šˆ์˜ ์•„๋ž˜๋ฅผ ํ™•์ธํ•˜๊ณ  ์ž‘์—…์‹œ์ž‘ ๋˜๋Š” ์ž‘์—…์š”์ฒญ์„ ํ•ด์ฃผ์„ธ์š”.

  1. ์•„๋ž˜์˜ ๋ฒˆ์—ญ ๋ฆฌ์ŠคํŠธ๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
  2. ๋ฒˆ์—ญ์„ ํ•˜๊ณ  ์‹ถ์€ ๋‚ด์šฉ ๋˜๋Š” ๊ด€์‹ฌ์ด ์žˆ๋Š” ๋‚ด์šฉ์ด ์žˆ์„ ๊ฒฝ์šฐ Comment ๋˜๋Š” Issue ๋ฅผ ๋‚จ๊ฒจ์ฃผ์„ธ์š”(์˜ˆ์‹œ. ๋ฒˆ์—ญํฌ๋ง ์˜ˆ์‹œ )
    3, Contributor๊ฐ€ ๋˜์—ˆ๋‹ค๋ฉด ๋ฒˆ์—ญํ•˜๊ณ  ์‹ถ๊ฑฐ๋‚˜ ๊ด€์‹ฌ์žˆ๋Š” ๋‚ด์šฉ์— ์ž์‹ ์„ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. (:heavy_check_mark:ํ•œ๋ฒˆ์— ํ• ๋‹น ์ตœ๋Œ€ 3๊ฐœ)
  3. Repo๋ฅผ Clone๋ฐ›๊ณ , ์ž์‹ ์ด Checkํ•œ ํ•ญ๋ชฉ์˜ ๋ฒˆ์—ญ ์ž‘์—… ํ›„ PR ํ•ด์ฃผ์„ธ์š”.
    • Commit Message ์–‘์‹ => :bookmark: <YOUR_NAME< / Translate / <MESSAGE>
  4. ๊ผญ ๋งž์ถค๋ฒ• ํ•œ๋ฒˆ์”ฉ ํ™•์ธํ•ด์ฃผ์„ธ์š”.
  5. ์ฐธ๊ณ  ๋ฒˆ์—ญ์ง‘์„ ์ฐธ๊ณ ํ•ด์ฃผ์‹œ๊ณ  ์ถ”๊ฐ€ํ•  ๋‚ด์šฉ์„ issue ๋˜๋Š” ์ถ”๊ฐ€ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”

๋ฒˆ์—ญ๋œ ๋‚ด์šฉ์„ PR๋กœ ์˜ฌ๋ฆฌ๊ธฐ

๋ฒˆ์—ญ๋œ ๋‚ด์šฉ์€ ์ž์‹ ์žˆ๊ฒŒ PR์„ ๋‚ ๋ ค์ฃผ์„ธ์š”. ๊ทธ ์ „์— ์•„๋ž˜์˜ ๋‚ด์šฉ์„ ์ฝ์–ด ์ฃผ์„ธ์š”

  • PR ๋Œ€์ƒ์ด ๋˜๋Š” Repo๋Š” SeonHyungJo/reactjs-interview-questions-korean ์ž…๋‹ˆ๋‹ค.
  • ํ•ด๋‹น Repo ์„ ํƒ์‹œ TEMPLATE๊ฐ€ ๋‚˜์˜ค๋ฉด ํ™•์ธ์„ ํ•˜๊ณ  ์ฒดํฌ๋ฅผ ํ•ฉ๋‹ˆ๋‹ค.
  • PR์‹œ ํ™•์ธ์š”์ฒญ label์„ ๋‹ฌ์•„์ค๋‹ˆ๋‹ค.
  • PR์„ ๋‚ ๋ ค์ค๋‹ˆ๋‹ค.

๋ฒˆ์—ญ ์ˆœ์„œ

  1. React Core
  2. React Router
  3. React Redux
  4. React supported libraries and Integration
  5. Miscellaneous
  6. ์ด์™ธ

์œ„์˜ ์ˆœ์„œ์— ๋งž๊ฒŒ ๋ฒˆ์—ญ์„ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

๋ฒˆ์—ญ ๋ฆฌ์ŠคํŠธ

๋ฒˆ์—ญ์€ ์ˆœ์„œ๋Œ€๋กœ ์ง„ํ–‰์„ ์•ˆํ•˜์…”๋„ ๋ฉ๋‹ˆ๋‹ค. ์ž์‹ ์ด ์ž์‹ ์žˆ๊ฑฐ๋‚˜ ํ•˜๊ณ ์‹ถ์€ ํ•ญ๋ชฉํ•˜์„ธ์š”

No. Questions Completed Translator
Core React - -
1 What is React? โ˜‘๏ธ @SeonHyungJo
2 What are the major features of React? โ˜‘๏ธ @SeonHyungJo
3 What is JSX? โ˜‘๏ธ @SeonHyungJo
4 What is the difference between Element and Component? โ˜‘๏ธ @SeonHyungJo
5 How to create components in React? โ˜‘๏ธ @SeonHyungJo
6 When to use a Class Component over a Function Component? โ˜‘๏ธ @BKJang
7 What are Pure Components? โ˜‘๏ธ @BKJang
8 What is state in React? โ˜‘๏ธ @BKJang
9 What are props in React? โ˜‘๏ธ @BKJang
10 What is the difference between state and props? โ˜‘๏ธ @BKJang
11 Why should we not update the state directly? โ˜‘๏ธ @SeonHyungJo
12 What is the purpose of callback function as an argument of setState()? โ˜‘๏ธ @SeonHyungJo
13 What is the difference between HTML and React event handling? โ˜‘๏ธ @SeonHyungJo
14 How to bind methods or event handlers in JSX callbacks? โ˜‘๏ธ @SeonHyungJo
15 How to pass a parameter to an event handler or callback? โ˜‘๏ธ @SeonHyungJo
16 What are synthetic events in React? โ˜‘๏ธ @SeonHyungJo
17 What is inline conditional expressions? โ˜‘๏ธ @SeonHyungJo
18 What are "key" props and what is the benefit of using them in arrays of elements? โ˜‘๏ธ @SeonHyungJo
19 What is the use of refs? โ˜‘๏ธ @BKJang
20 How to create refs? โ˜‘๏ธ @BKJang
21 What are forward refs? โ˜‘๏ธ @BKJang
22 Which is preferred option with in callback refs and findDOMNode()? โ˜‘๏ธ @SeonHyungJo
23 Why are String Refs legacy? โ˜‘๏ธ @SeonHyungJo
24 What is Virtual DOM? โ˜‘๏ธ @SeonHyungJo
25 How Virtual DOM works? โ˜‘๏ธ @SeonHyungJo
26 What is the difference between Shadow DOM and Virtual DOM? โ˜‘๏ธ @SeonHyungJo
27 What is React Fiber? โ˜‘๏ธ @SeonHyungJo
28 What is the main goal of React Fiber? โ˜‘๏ธ @SeonHyungJo
29 What are controlled components? โ˜‘๏ธ @SeonHyungJo
30 What are uncontrolled components? โ˜‘๏ธ @SeonHyungJo
31 What is the difference between createElement and cloneElement? โ˜‘๏ธ @SeonHyungJo
32 What is Lifting State Up in React? โ˜‘๏ธ @SeonHyungJo
33 What are the different phases of component lifecycle? โ˜‘๏ธ @SeonHyungJo
34 What are the lifecycle methods of React? โ˜‘๏ธ @SeonHyungJo
35 What are Higher-Order components? โ˜‘๏ธ @SeonHyungJo
36 How to create props proxy for HOC component? โ˜‘๏ธ @SeonHyungJo
37 What is context? โ˜‘๏ธ @SeonHyungJo
38 What is children prop? โ˜‘๏ธ @BKJang
39 How to write comments in React? โ˜‘๏ธ @BKJang
40 What is the purpose of using super constructor with props argument? โ˜‘๏ธ @BKJang
41 What is reconciliation? โ˜‘๏ธ @SeonHyungJo
42 How to set state with a dynamic key name? โ˜‘๏ธ @SeonHyungJo
43 What would be the common mistake of function being called every time the component renders? โ˜‘๏ธ @SeonHyungJo
44 Why is it necessary to capitalize component names? โ˜‘๏ธ @SeonHyungJo
45 Why React uses className over class attribute? โ˜‘๏ธ @SeonHyungJo
46 What are fragments? โ˜‘๏ธ @SeonHyungJo
47 Why fragments are better than container divs? โ˜‘๏ธ @SeonHyungJo
48 What are portals in React? โ˜‘๏ธ @SeonHyungJo
49 What are stateless components? โ˜‘๏ธ @SeonHyungJo
50 What are stateful components? โ˜‘๏ธ @SeonHyungJo
51 How to apply validation on props in React? โ˜‘๏ธ @SeonHyungJo
52 What are the advantages of React? โ˜‘๏ธ @SeonHyungJo
53 What are the limitations of React? โ˜‘๏ธ @SeonHyungJo
54 What are error boundaries in React v16 โ˜‘๏ธ @SeonHyungJo
55 How error boundaries handled in React v15? โ˜‘๏ธ @SeonHyungJo
56 What are the recommended ways for static type checking? โ˜‘๏ธ @SeonHyungJo
57 What is the use of react-dom package? โ˜‘๏ธ @SeonHyungJo
58 What is the purpose of render method of react-dom? โ˜‘๏ธ @SeonHyungJo
59 What is ReactDOMServer? โ˜‘๏ธ @SeonHyungJo
60 How to use InnerHtml in React? โ˜‘๏ธ @SeonHyungJo
61 How to use styles in React? โ˜‘๏ธ @SeonHyungJo
62 How events are different in React? โ˜‘๏ธ @SeonHyungJo
63 What will happen if you use setState in constructor? โ˜‘๏ธ @SeonHyungJo
64 What is the impact of indexes as keys? โ˜‘๏ธ @SeonHyungJo
65 Is it good to use setState() in componentWillMount() method? โ˜‘๏ธ @SeonHyungJo
66 What will happen if you use props in initial state? โ˜‘๏ธ @SeonHyungJo
67 How do you conditionally render components? โ˜‘๏ธ @SeonHyungJo
68 Why we need to be careful when spreading props on DOM elements?? โ˜‘๏ธ @SeonHyungJo
69 How you use decorators in React? โ˜‘๏ธ @SeonHyungJo
70 How do you memoize a component? โ˜‘๏ธ @SeonHyungJo
71 How you implement Server-Side Rendering or SSR? โ˜‘๏ธ @SeonHyungJo
72 How to enable production mode in React? โ˜‘๏ธ @SeonHyungJo
73 What is CRA and its benefits? โ˜‘๏ธ @SeonHyungJo
74 What is the lifecycle methods order in mounting? โ˜‘๏ธ @SeonHyungJo
75 What are the lifecycle methods going to be deprecated in React v16? โ˜‘๏ธ @SeonHyungJo
76 What is the purpose of getDerivedStateFromProps() lifecycle method? โ˜‘๏ธ @SeonHyungJo
77 What is the purpose of getSnapshotBeforeUpdate() lifecycle method? โ˜‘๏ธ @SeonHyungJo
78 What is the difference between createElement() and cloneElement() methods? โ˜‘๏ธ @SeonHyungJo
79 What is the recommended way for naming components? โ˜‘๏ธ @SeonHyungJo
80 What is the recommended ordering of methods in component class? โ˜‘๏ธ @SeonHyungJo
81 What is a switching component? โ˜‘๏ธ @SeonHyungJo
82 Why we need to pass a function to setState()? โ˜‘๏ธ @SeonHyungJo
83 What is strict mode in React? โ˜‘๏ธ @SeonHyungJo
84 What are React Mixins? โ˜‘๏ธ @SeonHyungJo
85 Why is isMounted() an anti-pattern and what is the proper solution? โ˜‘๏ธ @SeonHyungJo
86 What are the Pointer Events supported in React? โ˜‘๏ธ @SeonHyungJo
87 Why should component names start with capital letter? โ˜‘๏ธ @SeonHyungJo
88 Are custom DOM attributes supported in React v16? โ˜‘๏ธ @SeonHyungJo
89 What is the difference between constructor and getInitialState? โ˜‘๏ธ @SeonHyungJo
90 Can you force a component to re-render without calling setState? โ˜‘๏ธ @SeonHyungJo
91 What is the difference between super() and super(props) in React using ES6 classes? โ˜‘๏ธ @SeonHyungJo
92 How to loop inside JSX? โ˜‘๏ธ @SeonHyungJo
93 How do you access props in attribute quotes? โ˜‘๏ธ @SeonHyungJo
94 What is React PropType array with shape? โ˜‘๏ธ @SeonHyungJo
95 How conditionally apply class attributes? โ˜‘๏ธ @SeonHyungJo
96 What is the difference between React and ReactDOM? โ˜‘๏ธ @SeonHyungJo
97 Why ReactDOM is separated from React? โ˜‘๏ธ @SeonHyungJo
98 How to use React label element? โ˜‘๏ธ @SeonHyungJo
99 How to combine multiple inline style objects? โ˜‘๏ธ @SeonHyungJo
100 How to re-render the view when the browser is resized? โ˜‘๏ธ @SeonHyungJo
101 What is the difference between setState and replaceState methods? โ˜‘๏ธ @SeonHyungJo
102 How to listen to state changes? โ˜‘๏ธ @SeonHyungJo
103 What is the recommended approach of removing an array element in react state? โ˜‘๏ธ @SeonHyungJo
104 Is it possible to use React without rendering HTML? โ˜‘๏ธ @SeonHyungJo
105 How to pretty print JSON with React? โ˜‘๏ธ @SeonHyungJo
106 Why you can't update props in React? โ˜‘๏ธ @SeonHyungJo
107 How to focus an input element on page load? โ˜‘๏ธ @SeonHyungJo
108 What are the possible ways of updating objects in state? โ˜‘๏ธ @SeonHyungJo
109 Why function is preferred over object for setState? โ˜‘๏ธ @SeonHyungJo
110 How can we find the version of React at runtime in the browser? โ˜‘๏ธ @SeonHyungJo
111 What are the approaches to include polyfills in your create-react-app? โ˜‘๏ธ @SeonHyungJo
112 How to use https instead of http in create-react-app? โ˜‘๏ธ @SeonHyungJo
113 How to avoid using relative path imports in create-react-app? โ˜‘๏ธ @SeonHyungJo
114 How to add Google Analytics for react-router? โ˜‘๏ธ @SeonHyungJo
115 How to update a component every second? โ˜‘๏ธ @SeonHyungJo
116 How do you apply vendor prefixes to inline styles in React? โ˜‘๏ธ @SeonHyungJo
117 How to import and export components using react and ES6? โ˜‘๏ธ @SeonHyungJo
118 Why React component names must begin with a capital letter? โ˜‘๏ธ @SeonHyungJo
119 Why is a component constructor called only once? โ˜‘๏ธ @SeonHyungJo
120 How to define constants in React? โ˜‘๏ธ @SeonHyungJo
121 How to programmatically trigger click event in React? โ˜‘๏ธ @SeonHyungJo
122 Is it possible to use async/await in plain React? โ˜‘๏ธ @SeonHyungJo
123 What are the common folder structures for React? โ˜‘๏ธ @SeonHyungJo
124 What are the popular packages for animation? โ˜‘๏ธ @SeonHyungJo
125 What is the benefit of styles modules? โ˜‘๏ธ @SeonHyungJo
126 What are the popular React-specific linters? โ˜‘๏ธ @SeonHyungJo
127 How to make AJAX call and In which component lifecycle methods should I make an AJAX call? โ˜‘๏ธ @SeonHyungJo
128 What are render props? โ˜‘๏ธ @SeonHyungJo
React Router
129 What is React Router? โ˜‘๏ธ @SeonHyungJo
130 How React Router is different from history library? โ˜‘๏ธ @SeonHyungJo
131 What are the <Router> components of React Router v4? โ˜‘๏ธ @SeonHyungJo
132 What is the purpose of push and replace methods of history? โ˜‘๏ธ @SeonHyungJo
133 How do you programmatically navigate using React router v4? โ˜‘๏ธ @SeonHyungJo
134 How to get query parameters in React Router v4 โ˜‘๏ธ @SeonHyungJo
135 Why you get "Router may have only one child element" warning? โ˜‘๏ธ @SeonHyungJo
136 How to pass params to history.push method in React Router v4? โ˜‘๏ธ @SeonHyungJo
137 How to implement default or NotFound page? โ˜‘๏ธ @SeonHyungJo
138 How to get history on React Router v4? โ˜‘๏ธ @SeonHyungJo
139 How to perform automatic redirect after login? โ˜‘๏ธ @SeonHyungJo
React Internationalization
140 What is React-Intl?
141 What are the main features of React Intl?
142 What are the two ways of formatting in React Intl?
143 How to use FormattedMessage as placeholder using React Intl?
144 How to access current locale with React Intl
145 How to format date using React Intl?
React Testing
146 What is Shallow Renderer in React testing?
147 What is TestRenderer package in React?
148 What is the purpose of ReactTestUtils package?
149 What is Jest?
150 What are the advantages of Jest over Jasmine?
151 Give a simple example of Jest test case
React Redux
152 What is Flux? โ˜‘๏ธ @SeonHyungJo
153 What is Redux? โ˜‘๏ธ @SeonHyungJo
154 What are the core principles of Redux? โ˜‘๏ธ @SeonHyungJo
155 What are the downsides of Redux compared to Flux? โ˜‘๏ธ @SeonHyungJo
156 What is the difference between mapStateToProps() and mapDispatchToProps()? โ˜‘๏ธ @SeonHyungJo
157 Can I dispatch an action in reducer? โ˜‘๏ธ @SeonHyungJo
158 How to access Redux store outside a component? โ˜‘๏ธ @SeonHyungJo
159 What are the drawbacks of MVW pattern โ˜‘๏ธ @SeonHyungJo
160 Are there any similarities between Redux and RxJS? โ˜‘๏ธ @SeonHyungJo
161 How to dispatch an action on load? โ˜‘๏ธ @SeonHyungJo
162 How to use connect from React Redux? โ˜‘๏ธ @SeonHyungJo
163 How to reset state in Redux? โ˜‘๏ธ @SeonHyungJo
164 Whats the purpose of at symbol in the redux connect decorator? โ˜‘๏ธ @SeonHyungJo
165 What is the difference between React context and React Redux? โ˜‘๏ธ @SeonHyungJo
166 Why are Redux state functions called reducers? โ˜‘๏ธ @SeonHyungJo
167 How to make AJAX request in Redux? โ˜‘๏ธ @SeonHyungJo
168 Should I keep all component's state in Redux store? โ˜‘๏ธ @SeonHyungJo
169 What is the proper way to access Redux store? โ˜‘๏ธ @SeonHyungJo
170 What is the difference between component and container in React Redux? โ˜‘๏ธ @SeonHyungJo
171 What is the purpose of the constants in Redux? โ˜‘๏ธ @SeonHyungJo
172 What are the different ways to write mapDispatchToProps()? โ˜‘๏ธ @SeonHyungJo
173 What is the use of the ownProps parameter in mapStateToProps() and mapDispatchToProps()? โ˜‘๏ธ @SeonHyungJo
174 How to structure Redux top level directories? โ˜‘๏ธ @SeonHyungJo
175 What is redux-saga? โ˜‘๏ธ @SeonHyungJo
176 What is the mental model of redux-saga? โ˜‘๏ธ @SeonHyungJo
177 What are the differences between call and put in redux-saga โ˜‘๏ธ @SeonHyungJo
178 What is Redux Thunk? โ˜‘๏ธ @SeonHyungJo
179 What are the differences between redux-saga and redux-thunk โ˜‘๏ธ @SeonHyungJo
180 What is Redux DevTools? โ˜‘๏ธ @SeonHyungJo
181 What are the features of Redux DevTools? โ˜‘๏ธ @SeonHyungJo
182 What are Redux selectors and Why to use them? โ˜‘๏ธ @SeonHyungJo
183 What is Redux Form? โ˜‘๏ธ @SeonHyungJo
184 What are the main features of Redux Form? โ˜‘๏ธ @SeonHyungJo
185 How to add multiple middlewares to Redux? โ˜‘๏ธ @SeonHyungJo
186 How to set initial state in Redux? โ˜‘๏ธ @SeonHyungJo
187 How Relay is different from Redux? โ˜‘๏ธ @SeonHyungJo
React Native
188 What is the difference between React Native and React?
189 How to test React Native apps?
190 How to do logging in React Native?
191 How to debug your React Native?
React supported libraries and Integration
192 What is reselect and how it works? โ˜‘๏ธ @SeonHyungJo
193 What is Flow? โ˜‘๏ธ @SeonHyungJo
194 What is the difference between Flow and PropTypes? โ˜‘๏ธ @SeonHyungJo
195 How to use font-awesome icons in React? โ˜‘๏ธ @SeonHyungJo
196 What is React Dev Tools? โ˜‘๏ธ @SeonHyungJo
197 Why is DevTools not loading in Chrome for local files? โ˜‘๏ธ @SeonHyungJo
198 How to use Polymer in React? โ˜‘๏ธ @SeonHyungJo
199 What are the advantages of React over Vue.js? โ˜‘๏ธ @SeonHyungJo
200 What is the difference between React and Angular? โ˜‘๏ธ @SeonHyungJo
201 Why React tab is not showing up in DevTools? โ˜‘๏ธ @SeonHyungJo
202 What are styled components? โ˜‘๏ธ @SeonHyungJo
203 Give an example of Styled Components? โ˜‘๏ธ @SeonHyungJo
204 What is Relay? โ˜‘๏ธ @SeonHyungJo
205 How to use TypeScript in create-react-app application? โ˜‘๏ธ @SeonHyungJo
Miscellaneous
206 What are the main features of reselect library? โ˜‘๏ธ @SeonHyungJo
207 Give an example of reselect usage? โ˜‘๏ธ @SeonHyungJo
208 What is an action in Redux? โ˜‘๏ธ @SeonHyungJo
209 Does the statics object work with ES6 classes in React? โ˜‘๏ธ @SeonHyungJo
210 Can Redux only be used with React? โ˜‘๏ธ @SeonHyungJo
211 Do you need to have a particular build tool to use Redux? โ˜‘๏ธ @SeonHyungJo
212 How Redux Form initialValues get updated from state? โ˜‘๏ธ @SeonHyungJo
213 How React PropTypes allow different type for one prop? โ˜‘๏ธ @SeonHyungJo
214 Can I import an SVG file as react component? โ˜‘๏ธ @SeonHyungJo
215 Why are inline ref callbacks or functions not recommended? โ˜‘๏ธ @SeonHyungJo
216 What is render hijacking in React? โ˜‘๏ธ @SeonHyungJo
217 What are HOC factory implementations? โ˜‘๏ธ @SeonHyungJo
218 How to pass numbers to React component? โ˜‘๏ธ @SeonHyungJo
219 Do I need to keep all my state into Redux? Should I ever use react internal state? โ˜‘๏ธ @SeonHyungJo
220 What is the purpose of registerServiceWorker in React? โ˜‘๏ธ @SeonHyungJo
221 What is React memo function? โ˜‘๏ธ @SeonHyungJo
222 What is React lazy function? โ˜‘๏ธ @SeonHyungJo
223 How to prevent unnecessary updates using setState? โ˜‘๏ธ @SeonHyungJo
224 How do you render Array, Strings and Numbers in React 16 Version? โ˜‘๏ธ @SeonHyungJo
225 How to use class field declarations syntax in React classes? โ˜‘๏ธ @SeonHyungJo
226 What are hooks? โ˜‘๏ธ @SeonHyungJo
227 What are the rules needs to follow for hooks? โ˜‘๏ธ @SeonHyungJo
228 How to ensure hooks followed the rules in your project? โ˜‘๏ธ @SeonHyungJo
229 What are the differences between Flux and Redux? โ˜‘๏ธ @SeonHyungJo
230 What are the benefits of React Router V4? โ˜‘๏ธ @SeonHyungJo
231 Can you describe about componentDidCatch lifecycle method signature? โ˜‘๏ธ @SeonHyungJo
232 In which scenarios error boundaries do not catch errors? โ˜‘๏ธ @SeonHyungJo
233 Why do not you need error boundaries for event handlers? โ˜‘๏ธ @SeonHyungJo
234 What is the difference between try cath block and error boundaries? โ˜‘๏ธ @SeonHyungJo
235 What is the behavior of uncaught errors in react 16? โ˜‘๏ธ @SeonHyungJo
236 What is the proper placement for error boundaries? โ˜‘๏ธ @SeonHyungJo
237 What is the benefit of component stack trace from error boundary? โ˜‘๏ธ @SeonHyungJo
238 What is the required method to be defined for a class component? โ˜‘๏ธ @SeonHyungJo
239 What are the possible return types of render method? โ˜‘๏ธ @SeonHyungJo
240 What is the main purpose of constructor? โ˜‘๏ธ @SeonHyungJo
241 Is it mandatory to define constructor for React component? โ˜‘๏ธ @SeonHyungJo
242 What are default props? โ˜‘๏ธ @SeonHyungJo
243 Why should not call setState in componentWillUnmount? โ˜‘๏ธ @SeonHyungJo
244 What is the purpose of getDerivedStateFromError? โ˜‘๏ธ @SeonHyungJo
245 What is the methods order when component re-rendered? โ˜‘๏ธ @SeonHyungJo
246 What are the methods invoked during error handling? โ˜‘๏ธ @SeonHyungJo
247 What is the purpose of displayName class property? โ˜‘๏ธ @SeonHyungJo
248 What is the browser support for react applications? โ˜‘๏ธ @SeonHyungJo
249 What is the purpose of unmountComponentAtNode method? โ˜‘๏ธ @SeonHyungJo
250 What is code-splitting? โ˜‘๏ธ @SeonHyungJo
251 What is the benefit of strict mode? โ˜‘๏ธ @SeonHyungJo
252 What are Keyed Fragments? โ˜‘๏ธ @SeonHyungJo
253 Is it React support all HTML attributes? โ˜‘๏ธ @SeonHyungJo
254 What are the limitations with HOCs? โ˜‘๏ธ @SeonHyungJo
255 How to debug forwardRefs in DevTools? โ˜‘๏ธ @SeonHyungJo
256 When component props defaults to true? โ˜‘๏ธ @SeonHyungJo
257 What is NextJS and major features of it? โ˜‘๏ธ @SeonHyungJo
258 How do you pass an event handler to a component? โ˜‘๏ธ @SeonHyungJo
259 Is it good to use arrow functions in render methods? โ˜‘๏ธ @SeonHyungJo
260 How to prevent a function from being called multiple times? โ˜‘๏ธ @SeonHyungJo
261 How JSX prevents Injection Attacks? โ˜‘๏ธ @SeonHyungJo
262 How do you update rendered elements? โ˜‘๏ธ @SeonHyungJo
263 How do you say that props are read only? โ˜‘๏ธ @SeonHyungJo
264 How do you say that state updates are merged? โ˜‘๏ธ @SeonHyungJo
265 How do you pass arguments to an event handler? โ˜‘๏ธ @SeonHyungJo
266 How to prevent component from rendering? โ˜‘๏ธ @SeonHyungJo
267 What are the conditions to safely use the index as a key? โ˜‘๏ธ @SeonHyungJo
268 Is it keys should be globally unique? โ˜‘๏ธ @SeonHyungJo
269 What is the popular choice for form handling? โ˜‘๏ธ @SeonHyungJo
270 What are the advantages of formik over redux form library? โ˜‘๏ธ @SeonHyungJo
271 Why do you not required to use inheritance? โ˜‘๏ธ @SeonHyungJo
272 Can I use web components in react application? โ˜‘๏ธ @SeonHyungJo
273 What is dynamic import? โ˜‘๏ธ @SeonHyungJo
274 What are loadable components? โ˜‘๏ธ @SeonHyungJo
275 What is suspense component? โ˜‘๏ธ @SeonHyungJo
276 What is route based code splitting? โ˜‘๏ธ @SeonHyungJo
277 Give an example on How to use context? โ˜‘๏ธ @SeonHyungJo
278 What is the purpose of default value in context? โ˜‘๏ธ @SeonHyungJo
279 How do you use contextType? โ˜‘๏ธ @SeonHyungJo
280 What is a consumer? โ˜‘๏ธ @SeonHyungJo
281 How do you solve performance corner cases while using context? โ˜‘๏ธ @SeonHyungJo
282 What is the purpose of forward ref in HOCs? โ˜‘๏ธ @SeonHyungJo
283 Is it ref argument available for all functions or class components? โ˜‘๏ธ @SeonHyungJo
284 Why do you need additional care for component libraries while using forward refs? โ˜‘๏ธ @SeonHyungJo
285 How to create react class components without ES6? โ˜‘๏ธ @SeonHyungJo
286 Is it possible to use react without JSX? โ˜‘๏ธ @SeonHyungJo
287 What is diffing algorithm? โ˜‘๏ธ @SeonHyungJo
288 What are the rules covered by diffing algorithm? โ˜‘๏ธ @SeonHyungJo
289 When do you need to use refs? โ˜‘๏ธ @SeonHyungJo
290 Is it prop must be named as render for render props? โ˜‘๏ธ @SeonHyungJo
291 What are the problems of using render props with pure components? โ˜‘๏ธ @SeonHyungJo
292 How do you create HOC using render props? โ˜‘๏ธ @SeonHyungJo
293 What is windowing technique? โ˜‘๏ธ @SeonHyungJo
294 How do you print falsy values in JSX? โ˜‘๏ธ @SeonHyungJo
295 What is the typical use case of portals? โ˜‘๏ธ @SeonHyungJo
296 How do you set default value for uncontrolled component? โ˜‘๏ธ @SeonHyungJo
297 What is your favorite React stack? โ˜‘๏ธ @SeonHyungJo
298 What is the difference between Real DOM and Virtual DOM? โ˜‘๏ธ @SeonHyungJo
299 How to add a bootstrap for a react application? โ˜‘๏ธ @SeonHyungJo
300 Can you list down top websites or applications using react as front end framework? โ˜‘๏ธ @SeonHyungJo
301 Is it recommended to use CSS In JS technique in React? โ˜‘๏ธ @SeonHyungJo
302 Do I need to rewrite all my class components with hooks? โ˜‘๏ธ @SeonHyungJo
303 How to fetch data with React Hooks? โ˜‘๏ธ @SeonHyungJo
304 Is Hooks cover all use cases for classes? โ˜‘๏ธ @SeonHyungJo
305 What is the stable release for hooks support? โ˜‘๏ธ @SeonHyungJo
306 Why do we use square brackets in useState? โ˜‘๏ธ @SeonHyungJo
307 What are the sources used for introducing hooks? โ˜‘๏ธ @SeonHyungJo
308 How do you access imperative API of web components? โ˜‘๏ธ @SeonHyungJo
309 What is formik? โ˜‘๏ธ @SeonHyungJo
310 What are typical middleware choices for handling asynchronous calls in Redux? โ˜‘๏ธ @SeonHyungJo
311 Is browsers understand JSX code? โ˜‘๏ธ @SeonHyungJo
312 Describe about data flow in react? โ˜‘๏ธ @SeonHyungJo
313 What is react scripts? โ˜‘๏ธ @SeonHyungJo
314 What are the features of create react app? โ˜‘๏ธ @SeonHyungJo
315 What is the purpose of renderToNodeStream method? โ˜‘๏ธ @SeonHyungJo
316 What is MobX? โ˜‘๏ธ @SeonHyungJo
317 What are the differences between Redux and MobX? โ˜‘๏ธ @SeonHyungJo
318 Should I learn ES6 before learning ReactJS? โ˜‘๏ธ @SeonHyungJo
319 What is Concurrent Rendering? โ˜‘๏ธ @SeonHyungJo
320 What is the difference between async mode and concurrent mode? โ˜‘๏ธ @SeonHyungJo
321 Can I use javascript urls in react16.9? โ˜‘๏ธ @SeonHyungJo
322 What is the purpose of eslint plugin for hooks? โ˜‘๏ธ @SeonHyungJo
323 What is the difference between Imperative and Declarative in React? โ˜‘๏ธ @SeonHyungJo
324 What are the benefits of using typescript with reactjs? โ˜‘๏ธ @SeonHyungJo
325 How do you make sure that user remains authenticated on page refresh while using Context API State Management? โ˜‘๏ธ @dididy
326 What are the benefits of new JSX transform? โ˜‘๏ธ @SeonHyungJo
327 How does new JSX transform different from old transform? โ˜‘๏ธ @SeonHyungJo
328 How do you get redux scaffolding using create-react-app? @SeonHyungJo
329 What are React Server components? @SeonHyungJo
330 What is prop drilling? @dididy
331 What are the different ways to prevent state mutation?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.