๋ฐ˜์‘ํ˜•

TL;DR


  • ๋งˆ์šดํŠธ : ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ตœ์ดˆ๋กœ DOM์— ์‚ฝ์ž…๋˜๋Š” ๊ณผ์ •. ์ปดํฌ๋„ŒํŠธ ์ƒ๋ช… ์ฃผ๊ธฐ์—์„œ ํ•œ ๋ฒˆ๋งŒ ๋ฐœ์ƒ
  • ๋ Œ๋” : ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‹คํ–‰ํ•ด์„œ ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ๊ณ„์‚ฐ(์ปดํฌ๋„ŒํŠธ ์ถœ๋ ฅ ๊ฒฐ์ •)ํ•˜๋Š” ๊ณผ์ •. ์ƒˆ๋กœ์šด ๊ฐ€์ƒ DOM์„ ์ƒ์„ฑํ•˜๊ณ  ์ด ์ƒˆ๋กœ์šด ๊ฐ€์ƒ DOM๊ณผ ์ด์ „ ๊ฐ€์ƒ DOM์„ ๋น„๊ตํ•˜์—ฌ ์‹ค์ œ DOM์— ๋ฐ˜์˜ํ•  ๋ณ€๊ฒฝ์‚ฌํ•ญ ํŒŒ์•…
  • ์ปค๋ฐ‹ : ๋ Œ๋” ๋‹จ๊ณ„๋ฅผ ํ†ตํ•ด ํŒŒ์•…๋œ ๋ณ€๊ฒฝ์‚ฌํ•ญ๋“ค์ด ์‹ค์ œ ๋ธŒ๋ผ์šฐ์ € DOM์— ์ ์šฉ๋˜๋Š” ๊ณผ์ •

 

๋ Œ๋”๋ง์ด๋ž€


์ผ๋ฐ˜์ ์œผ๋กœ ๋ Œ๋”๋ง(Rendering)์€ ์•„๋ž˜ 2๊ฐ€์ง€ ๊ณผ์ •์„ ์ง€์นญํ•œ๋‹ค.

 

  1. HTML / CSS / JS๋กœ ์ž‘์„ฑ๋œ ๋ฌธ์„œ๋ฅผ ํ•ด์„(ํŒŒ์‹ฑ)ํ•ด์„œ ๋ธŒ๋ผ์šฐ์ €์— ์‹œ๊ฐ์ ์œผ๋กœ ์ถœ๋ ฅํ•˜๋Š” ๊ณผ์ •
  2. ์„œ๋ฒ„์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ HTML๋กœ ๋ณ€ํ™˜ํ•ด์„œ ๋ธŒ๋ผ์šฐ์ €์—๊ฒŒ ์ „๋‹ฌํ•˜๋Š” ๊ณผ์ •(SSR)

 

๋ฐ˜๋ฉด ๋ฆฌ์•กํŠธ์—์„œ ๋งํ•˜๋Š” ๋ Œ๋”๋ง์€ ๋ธŒ๋ผ์šฐ์ € DOM ์ˆ˜์ • ๋น„์šฉ์„ ์ค„์ด๊ธฐ ์œ„ํ•ด ์ˆ˜ํ–‰ํ•˜๋Š” ์ž‘์—…์„ ์ผ์ปซ๋Š”๋‹ค. ์ด ์ž‘์—…์„ ํ†ตํ•ด ๋ธŒ๋ผ์šฐ์ € DOM์˜ ์—…๋ฐ์ดํŠธ ๋ฒ”์œ„๋ฅผ ๊ฒฐ์ •ํ•˜๊ณ  ๋ฐ˜์˜ํ•œ๋‹ค. ์ข€ ๋” ์—„๋ฐ€ํ•˜๊ฒŒ ๋งํ•˜๋ฉด props์™€ state๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ UI ์˜์—ญ์ด ์–ด๋–ป๊ฒŒ ๋ณด์ด๊ธธ ์›ํ•˜๋Š”์ง€, ์ปดํฌ๋„ŒํŠธ์—๊ฒŒ ์„ค๋ช…์„ ์š”์ฒญํ•˜๋Š” ๋ฆฌ์•กํŠธ ํ”„๋กœ์„ธ์Šค๋‹ค.

Rendering is the process of React asking your components to describe what they want their section of the UI to look like now, based on the current combination of props and state

 

๋ Œ๋”๋ง ๊ณผ์ •


โถ Trigger: ๋ Œ๋”๋ง ์œ ๋ฐœ

์•ฑ ์‹œ์ž‘ ์ดˆ๊ธฐ(initial render) ๋˜๋Š” state ๋ณ€๊ฒฝ์ด ์žˆ์„ ๋•Œ(re-render).

 

โท Render: ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ Œ๋”๋งํ•˜๊ณ  ๋ณ€๊ฒฝ์‚ฌํ•ญ ๊ณ„์‚ฐ

๋ธŒ๋ผ์šฐ์ € DOM์— ๋ฐ˜์˜๋  ์š”์†Œ๋ฅผ ๊ณ„์‚ฐํ•œ๋‹ค. ์ด ๋‹จ๊ณ„์—์„œ ๋ธŒ๋ผ์šฐ์ € DOM์„ ์—…๋ฐ์ดํŠธ ํ•˜๊ธฐ ์ „, ๊ฐ€์ƒ DOM์„ ์กฐ์ž‘ํ•ด์„œ ์—…๋ฐ์ดํŠธํ•  ๋ชจ์–‘์„ ๋งŒ๋“ค์–ด ๋‚ธ๋‹ค. ๋ธŒ๋ผ์šฐ์ € DOM์„ ์ง์ ‘ ์กฐ์ž‘ํ•˜๋Š” ๋น„์šฉ(repaint / reflow)์ด ํฌ๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ€์ƒ DOM์„ ํ†ตํ•ด ์—…๋ฐ์ดํŠธ๋ฅผ ๋ฏธ๋ฆฌ ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ. ์ดˆ๊ธฐ ๋ Œ๋”๋ผ๋ฉด ๋ฃจํŠธ ์ปดํฌ๋„ŒํŠธ๋ฅผ ํ˜ธ์ถœํ•ด์„œ ์ „์ฒด ์—˜๋ฆฌ๋จผํŠธ์— ๋Œ€ํ•œ ๊ฐ€์ƒ๋”์„ ๋งŒ๋“ค๊ณ , ๋ฆฌ๋ Œ๋”๋ผ๋ฉด ์ด์ „ ๋ Œ๋”์™€ ๋น„๊ตํ•ด์„œ ๋ณ€ํ™”๊ฐ€ ์žˆ๋Š” ์ปดํฌ๋„ŒํŠธ๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค.

 

โธ Commit: ๋ Œ๋” ๋‹จ๊ณ„์—์„œ ๊ณ„์‚ฐ๋œ ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ DOM์— ์ ์šฉ

Render ๋‹จ๊ณ„๋ฅผ ํ†ตํ•ด ํ˜ธ์ถœ๋œ ์ปดํฌ๋„ŒํŠธ๋“ค์ด ๋ธŒ๋ผ์šฐ์ € DOM์— ์ ์šฉ๋˜๋Š” ๋‹จ๊ณ„. ๋ Œ๋” ๋‹จ๊ณ„์—์„œ ๋ณ€ํ™”๊ฐ€ ์žˆ์—ˆ๋˜ ๋ถ€๋ถ„๋งŒ DOM์— ๋งˆ์šดํŠธ๋˜๊ณ  ๋ผ์ดํ”„์‚ฌ์ดํด์„ ์‹คํ–‰ํ•œ๋‹ค.

 

์žฌ์กฐ์ • | Reconciliation

React๋Š” ๋ Œ๋”๋ง ํ”„๋กœ์„ธ์Šค ๋™์•ˆ ์ปดํฌ๋„ŒํŠธ ํŠธ๋ฆฌ ์ „์ฒด์—์„œ ๋ Œ๋”๋ง ๊ฒฐ๊ณผ๋ฌผ์„ ์ˆ˜์ง‘ํ•œ๋‹ค. ๊ทธ ํ›„ ์ƒˆ๋กœ์šด ๊ฐ์ฒด ํŠธ๋ฆฌ(๊ฐ€์ƒ DOM)์™€ ๋น„๊ตํ•˜์—ฌ ๋ธŒ๋ผ์šฐ์ € DOM์„ ์›ํ•˜๋Š” ์ถœ๋ ฅ์œผ๋กœ ๋ณด์ด๊ธฐ ์œ„ํ•ด ๋ชจ๋“  ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ์ˆ˜์ง‘ํ•œ๋‹ค. ๋ฆฌ์•กํŠธ์—์„  ์ด๋ ‡๊ฒŒ ๋น„๊ตํ•˜๊ณ  ๊ณ„์‚ฐํ•˜๋Š” ๊ณผ์ •์„ ์žฌ์กฐ์ •(reconciliation)์ด๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค.

 

React === value UI

๋ฆฌ์•กํŠธ๋Š” ๊ฐ’(value) UI๋‹ค. ์ฆ‰, UI๋ฅผ ๋ฌธ์ž์—ด์ด๋‚˜ ๋ฐฐ์—ด๊ณผ ๊ฐ™์€ ๊ฐ’์œผ๋กœ ๋ณด๋Š” ๊ฐœ๋…์ด๋‹ค. ๊ฐ’์€ ๋ณ€์ˆ˜์— ์ €์žฅํ•˜๊ฑฐ๋‚˜ ์ „๋‹ฌํ•˜๊ณ , ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์ œ์–ด ํ๋ฆ„์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด์ฒ˜๋Ÿผ UI๋ฅผ ๊ฐ’์ฒ˜๋Ÿผ ์ œ์–ดํ•˜๋Š” ๋ฐฉ์‹์ด ๋ Œ๋”๋ง ํ”„๋กœ์„ธ์Šค์˜ ์ฃผ์š” ํฌ์ธํŠธ๋‹ค.

React is “value UI”. Its core principle is that UI is a value, just like a string or an array. You can keep it in a variable, pass it around, use JavaScript control flow with it, and so on. That expressiveness is the point — not some diffing to avoid applying changes to the DOM.
— via Mark’s Dev Blog

 

๋ ˆํผ๋Ÿฐ์Šค


 


๊ธ€ ์ˆ˜์ •์‚ฌํ•ญ์€ ๋…ธ์…˜ ํŽ˜์ด์ง€์— ๊ฐ€์žฅ ๋น ๋ฅด๊ฒŒ ๋ฐ˜์˜๋ฉ๋‹ˆ๋‹ค. ๋งํฌ๋ฅผ ์ฐธ๊ณ ํ•ด ์ฃผ์„ธ์š”
๋ฐ˜์‘ํ˜•