Skip to content

Latest commit

Β 

History

History
38 lines (30 loc) Β· 2 KB

File metadata and controls

38 lines (30 loc) Β· 2 KB

04. 폼 UI κ΅¬ν˜„ν•˜κΈ°: controlled vs uncontrolled

🎯 μš”κ΅¬ 사항

  • Header의 λ ˆμŠ€ν† λž‘ μΆ”κ°€ λ²„νŠΌμ„ ν΄λ¦­ν•˜λ©΄ λ ˆμŠ€ν† λž‘ μΆ”κ°€ 폼이 λͺ¨λ‹¬λ‘œ λœ¨λ„λ‘ κ΅¬ν˜„ν•΄ μ£Όμ„Έμš”
    • 이전 λ‹¨κ³„μ—μ„œ λ§Œλ“€μ–΄λ‘μ—ˆλ˜ AddRestaurantModal을 κ·ΈλŒ€λ‘œ μ‚¬μš©ν•©λ‹ˆλ‹€.
  • μΉ΄ν…Œκ³ λ¦¬λ₯Ό μ„ νƒν•˜κ³ , <input/>, <textarea/>에 값을 μž…λ ₯ν•œ λ’€ 'μΆ”κ°€ν•˜κΈ°' λ²„νŠΌμ„ ν΄λ¦­ν•˜λ©΄ λ ˆμŠ€ν† λž‘ λͺ©λ‘μ— μΆ”κ°€λ˜λ„λ‘ κ΅¬ν˜„ν•΄ μ£Όμ„Έμš”.
    • μœ νš¨μ„± κ²€μ‚¬λŠ” ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. μ•„μ£Ό κ°„λ‹¨ν•˜κ²Œ μž…λ ₯값을 μ²˜λ¦¬ν•΄λ³΄λŠ” κ΅¬ν˜„λ§Œ 해도 μΆ©λΆ„ν•©λ‹ˆλ‹€.
    • idλŠ” Date.now()값을 μž„μ˜λ‘œ ν• λ‹Ήν•©λ‹ˆλ‹€.
  • (optional) μž¬μ‚¬μš©ν•  수 μžˆλŠ” Modal μ»΄ν¬λ„ŒνŠΈλ₯Ό λ§Œλ“€μ–΄μ„œ AddRestaurantModal, RestaurantDetailModal을 Modal μ»΄ν¬λ„ŒνŠΈλ₯Ό ν™œμš©ν•΄ κ΅¬ν˜„ν•˜λŠ” κ²ƒμœΌλ‘œ κ°œμ„ ν•΄ λ³΄μ„Έμš”

βœ… ν‚€μ›Œλ“œ

  • controlled vs uncontrolled
  • children props

μž¬μ‚¬μš©ν•  수 μžˆλŠ” λͺ¨λ‹¬μ„ λ§Œλ“€ λ•Œ children을 ν™œμš©ν•΄ λ³΄μ„Έμš”. μ•„λž˜μ™€ 같은 μ‹μœΌλ‘œ UIλ₯Ό ꡬ성할 수 μžˆμŠ΅λ‹ˆλ‹€.

// μ„€λͺ…을 μœ„ν•œ μ˜ˆμ‹œμš© λ§ˆν¬μ—…μž…λ‹ˆλ‹€. μ‹€μ œλ‘œ μ‚¬μš©ν•˜λŠ” λ§ˆν¬μ—…μ€ template/ ν•˜μœ„μ˜ html을 μ°Έκ³ ν•˜κ±°λ‚˜ 직접 μ›ν•˜λŠ”λŒ€λ‘œ κ΅¬ν˜„ν•˜μ—¬ μ‚¬μš©ν•΄ μ£Όμ„Έμš”.
// λ°˜λ“œμ‹œ μ•„λž˜μ™€ 같은 ν˜•μ‹μœΌλ‘œ μ“Έ ν•„μš”λŠ” μ—†μŠ΅λ‹ˆλ‹€. μ›ν•˜λŠ” λ°©μ‹λŒ€λ‘œ μž¬μ‚¬μš© κ°€λŠ₯ν•œ <Modal/> μ»΄ν¬λ„ŒνŠΈλ₯Ό λ§Œλ“€μ–΄ λ³΄μ„Έμš”.

// AddRestaurantModal.jsx 
<Modal title="μƒˆλ‘œμš΄ μŒμ‹μ " onClose={onClose}>
  <form></form>
</Modal>

// RestaurantDetailModal.jsx 
<Modal title={restaurant.name} onClose={onClose}>
  <div className="restaurant-info"></div>
  <div className="button-container"></div>
</Modal>

πŸ§™β€β™€οΈ μ§„ν–‰ κ°€μ΄λ“œ

  • μ§„ν–‰ μ‹œκ°„: (optional μ œμ™Έ) 2μ‹œκ°„ 내에 μ™„λ£Œν•˜λŠ” 것을 λͺ©ν‘œλ‘œ ν•©λ‹ˆλ‹€.

πŸ”— μ°Έκ³  λ¬Έμ„œ