Skip to content

Latest commit

ย 

History

History
41 lines (30 loc) ยท 3.74 KB

DesignPattern.md

File metadata and controls

41 lines (30 loc) ยท 3.74 KB

1. Presentational Component - Container Component

  • ๋กœ์ง์„ ์ˆ˜ํ–‰ํ•˜๋Š” ์ปดํฌ๋„ŒํŠธ(= Container Component)์™€ UI๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๋งˆํฌ์—…(HTML, XML ๋“ฑ) ์ปดํฌ๋„ŒํŠธ(= Presentational Component)๋ฅผ ๋ถ„๋ฆฌ์‹œํ‚ค๋Š” ํŒจํ„ด
  • ๊ธฐ๋Šฅ ๋‹ด๋‹น๋ถ€์™€ ๋ทฐ ๋‹ด๋‹น๋ถ€๋ฅผ ๋ถ„๋ฆฌ์‹œ์ผœ ๋ชจ๋“ˆ์„ฑ, ์žฌ์‚ฌ์šฉ์„ฑ์ด ๋›ฐ์–ด๋‚œ ๋ฐฉ์‹. ๋‹ด๋‹น ์—ญํ• ์— ๋”ฐ๋ผ ๋ถ„๋ฆฌ๋˜์–ด์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋‹น์—ฐํžˆ ์œ ์ง€๋ณด์ˆ˜๋„ ๋” ์‰ฝ๋‹ค!
    • header์™€ footer๊ฐ™์ด ์—ฌ๋Ÿฌ ๊ณณ์—์„œ ๋ฐ˜๋ณต์ ์œผ๋กœ ์“ฐ์ด๋Š” ๋””์ž์ธ ์ปดํฌ๋„ŒํŠธ๋Š” props ๋ฅผ ํ†ตํ•ด ๋‹ค๋ฅธ ์ปดํฌ๋„ŒํŠธ๋กœ ์ „๋‹ฌํ•˜์—ฌ ์žฌ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
  • Container Component :
    • ๋ Œ๋”๋งํ•˜๊ณ ์ž ํ•˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ props์— ๋„ฃ์–ด ๋‹ค๋ฅธ ์ปจํ…Œ์ด๋„ˆ๋‚˜ presentation์œผ๋กœ ์ „๋‹ฌํ•œ๋‹ค
  • Presentational Component :
    • ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ ๋Šฅ๋ ฅ์ด ์—†๊ณ 
  • but, ๋กœ์ง๊ณผ ๋ทฐ๋ฅผ ๋ชจ๋‘ ๋ถ„๋ฆฌํ•˜๋Š” ๋ฐฉ์‹์ด๋ฏ€๋กœ ํŒŒ์ผ์˜ ์ˆ˜๊ฐ€ ๋Š˜์–ด๋‚œ๋‹ค๋Š” ์ ์ด ์žˆ๋‹ค.

2. Custom hook

  • ์—ญํ• ๋ณ„๋กœ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ถ„๋ฆฌํ•˜๋Š” ๊ฒƒ์— ์ง‘์ค‘ํ•œ ๋ฐฉ์‹
  • ๋”ฐ๋ผ์„œ ๋กœ์ง์ด ํ•˜๋Š” ๊ธฐ๋Šฅ์— ๋”ฐ๋ผ ๋ถ„ํ• ํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ๋ฐ˜๋ณต์ ์œผ๋กœ ํ•„์š”ํ•œ ๊ธฐ๋Šฅ์„ ๊ฐ€์ง„ ๋กœ์ง์„ ์žฌ์‚ฌ์šฉํ•˜๊ธฐ ์ข‹๋‹ค.
  • React ํ•จ์ˆ˜ ๋‚ด์—์„œ, ๊ทธ๋ฆฌ๊ณ  ์ตœ์ƒ์œ„์—์„œ ํ˜ธ์ถœ๋˜์–ด์•ผ๋งŒ ํ•˜๋ฉฐ, ์ด๋ฆ„์ด โ€œuseโ€๋กœ ์‹œ์ž‘ํ•ด์•ผ ํ•œ๋‹ค๋Š” ๊ทœ์น™์„ ๊ฐ€์ง„๋‹ค.
  • ์ฝ”๋“œ๊ฐ€ ๊ฐ„๊ฒฐํ•ด์ง„๋‹ค!

3. Atomic

  • ๊ฐ€์žฅ ์ž‘์€ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ฐ€์žฅ ์ž‘์€ ๋‹จ์œ„์ธ Atom์œผ๋กœ ์‚ผ๊ณ , ์•„ํ†ฐ์œผ๋กœ ์ด๋ฃจ์–ด์ง„ ์กฐํ•ฉ์œผ๋กœ ์ƒ์œ„ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ƒ๊ธฐ๋Š” ํŒจํ„ด์ด๋‹ค
  • ์•„ํ†ฐ๋ถ€ํ„ฐ ์ƒ์œ„ ์ปดํฌ๋„ŒํŠธ๋กœ ์˜ฌ๋ผ๊ฐ€๋Š” ๋‹จ๊ณ„๋Š” Atom โ†’ Molecules โ†’ Organisms โ†’ ํ…œํ”Œ๋ฆฟ โ†’ ํŽ˜์ด์ง€ ์ˆœ
  • ๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด ์†Œ์ž…์ž๊ฐ€ ๊ฒฐํ•ฉ์ฒด์—์„œ ์—ฌ๋Ÿฌ๋ฒˆ ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์žฌ์‚ฌ์šฉ์„ฑ์ด ๋†’๋‹ค
  • Atom : basic html elements (ex - button, title ๋“ฑ)
  • Molecules : ๋‘๊ฐœ ์ด์ƒ์˜ Atoms๋กœ ์ด๋ค„์ง€๋Š” ์ƒ์œ„ ๋‹จ์œ„ (ex- form, nav ๋“ฑ)
  • Templates : Atoms, Molecules, Organisms๊ฐ€ ์–ด๋–ป๊ฒŒ ์กฐํ•ฉ๋˜๋Š”์ง€์˜ ์„ค๊ณ„ ๊ตฌ์กฐ
  • Pages : Templates์˜ ๊ตฌ์กฐ๋ฅผ ๋””๋ฒจ๋กญ์‹œ์ผœ ์‹ค์ œ ์ปจํ…์ธ ๋ฅผ ๋ฐฐ์น˜ํ•ด UI๋ฅผ ์™„์„ฑํ•œ ๋‹จ์œ„
  • ๋‹ค๋งŒ ๊ณ„์ธต ๊ตฌ์กฐ์—ฌ์„œ ์ปดํฌ๋„ŒํŠธ ๊ฐ„์˜ ์ƒํ•˜๊ด€๊ณ„ ์˜์กด์„ฑ์ด ๊ฐ•ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์—๋Ÿฌ๊ฐ€ ์—ฐ์†์ ์œผ๋กœ ์ผ์–ด๋‚  ์ˆ˜ ์žˆ๋Š” ์œ„ํ—˜์„ฑ์ด ์žˆ๋‹ค.

์–ด๋–ค ๋ฐฉ์‹์„ ์–ธ์ œ ํƒํ•ด์•ผ ์ข‹์„์ง€?

  • 1๋ฒˆ : ํŠน์ • ๋ทฐ๋‚˜ ๋กœ์ง์ด ๋ฐ˜๋ณต๋˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์„ ๊ฒฝ์šฐ
  • 2๋ฒˆ : ๊ธฐ๋Šฅ๋“ค์ด ๋Œ€์ฒด๋กœ ๋ฐ˜๋ณต์ ์œผ๋กœ ์‚ฌ์šฉ๋˜๋Š” ๊ฒฝ์šฐ
  • 3๋ฒˆ : ์ปดํฌ๋„ŒํŠธ์˜ ์–‘์ด ๋งŽ๊ณ , ํŠน์ • ์ปดํฌ๋„ŒํŠธ๋งŒ ๋ฐ˜๋ณต๋˜๋Š” ๊ฒƒ์ด ์•„๋‹Œ, ์ „๋ฐ˜์ ์œผ๋กœ ์–ผํ‚ค๊ณ ์„คํ‚จ ํฌํ•จ๊ด€๊ณ„๋ฅผ ๊ฐ€์งˆ ๊ฒฝ์šฐ, ์ตœ๋Œ€ํ•œ ์ž‘์€ ๋‹จ์œ„๋กœ ๊ณ„์† ์กฐ๊ฐ๋‚ด์–ด ์žฌ์‚ฌ์šฉ์„ฑ์„ ๋†’์ด๋ฉด ์ข‹์„ ๊ฒƒ์ด๋‹ค. ๋˜ ์Šคํƒ€์ผ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ฐ”๊ฟ”์•ผํ•  ๋•Œ (์˜ˆ๋ฅผ๋“ค์–ด ํ”„๋กœ์ ํŠธ ๋‚ด ์‚ฌ์šฉํ•œ ๋ชจ๋“  ๋ฒ„ํŠผ์— ์ ์šฉ๋œ ํ…Œ๋งˆ ์ปฌ๋Ÿฌ๋ฅผ ์ผ๊ด„ ๋ณ€๊ฒฝํ•˜๊ณ ์ž ํ• ๋•Œ) ๋งค์šฐ ํŽธ๋ฆฌํ•˜๋‹ค.

ํ”„๋ก ํŠธ์—”๋“œ์—๊ฒŒ ๋””์ž์ธ ํŒจํ„ด์ด๋ž€?

์ง€๋‚œ ๊ณผ์ œ์˜€๋˜ ์›น์ตœ์ ํ™”๊ฐ€ ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ์ž์—๊ฒŒ ํ•„์š”ํ•œ ์ด์œ ์™€ ๋น„์Šทํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ•œ๋‹ค. ์›น์ตœ์ ํ™”๋„ ๋น ๋ฅธ ๋ Œ๋”๋ง ์‹œ๊ฐ„, ํ–ฅ์ƒ๋œ ์‚ฌ์šฉ์ž์˜ ๊ฒฝํ—˜์„ ์œ„ํ•ด ํ•„์š”ํ•˜๋‹ค๊ณ  ๋‹ต๋ณ€ํ–ˆ์—ˆ๋Š”๋ฐ, ํ”„๋ก ํŠธ์—”๋“œ ๋””์ž์ธ ํŒจํ„ด๋„ ๊ฒฐ๊ตญ ์ฝ”๋“œ์˜ โ€˜์žฌ์‚ฌ์šฉ์„ฑโ€™์„ ๋†’์ด๋Š” ํšจ๊ณผ๋ฅผ ๊ฐ€์ ธ์˜ค๊ธฐ ๋•Œ๋ฌธ์— ๋ถˆํ•„์š”ํ•œ ๋ฆฌ๋ Œ๋”๋ง์„ ์ค„์ด๋ฉฐ ํ–ฅ์ƒ๋œ ์‚ฌ์šฉ์ž ๊ฒฝํ—˜์„ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•œ๋‹ค. ๋”ฐ๋ผ์„œ ์‚ฌ์šฉ์ž๋ฅผ ์œ„ํ•ด ํ”„๋กœ์ ํŠธ์— ์ตœ์ ํ™”๋œ ๋””์ž์ธ ํŒจํ„ด์„ ์ ์ ˆํžˆ ์ž˜ ์ ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ•˜๋ฉฐ, ์–ด๋–ค ํ”„๋กœ์ ํŠธ์—ฌ๋„ โ€˜์œ ์ง€๋ณด์ˆ˜โ€™๊ฐ€ ์ •๋ง ์ค‘์š”ํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ์ •ํ•ด์ง„ ํŒจํ„ด/๊ทœ์น™์— ๋”ฐ๋ผ ์ฝ”๋“œ๋ฅผ ์ž˜ ๋ถ„ํ• ํ•˜๋Š” ๊ณผ์ •์€ ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ์— ๊ผญ ํ•„์š”ํ•œ ๊ฒƒ ๊ฐ™๋‹ค!!