Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐Ÿ”จ refactor: ์˜จ๋ณด๋”ฉ ํŽ˜์ด์ง€ ์ƒํƒœ๊ด€๋ฆฌ ๋ฆฌํŒฉํ† ๋ง #96

Merged
merged 17 commits into from
Feb 13, 2024

Conversation

bbearcookie
Copy link
Member

@bbearcookie bbearcookie commented Feb 11, 2024

๐Ÿงฉ ์ด์Šˆ ๋ฒˆํ˜ธ

โœ… ์ž‘์—… ์‚ฌํ•ญ

์‹คํ–‰ ํ™”๋ฉด

GOMCAM.20240212_0132560725.mp4

https://dnd-10th-4-frontend-ne5k21wv6-bbearcookie.vercel.app/onboarding Preview ์ฃผ์†Œ์—์„œ ์‹คํ–‰ ํ™•์ธ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค!

#64 ์—์„œ ์ž‘์—…ํ–ˆ๋˜ ๊ธฐ์กด ์˜จ๋ณด๋”ฉ ํŽ˜์ด์ง€์˜ ํผ ์ƒํƒœ๋Š” ๊ฐ ์Šคํ…์—์„œ ์ง€์—ญ ์ƒํƒœ๋กœ ๋‹ค๋ค„์ง€๊ณ , ๋‹ค์Œ ์Šคํ…์œผ๋กœ ๋„˜์–ด๊ฐ€๊ธฐ ์ „์— ๊ฐ๊ฐ API ํ˜ธ์ถœ์ด ๋ฐœ์ƒํ•˜๊ณ  ์žˆ์—ˆ๋Š”๋ฐ์š”. API ํ˜ธ์ถœ์ด ๋ฐฉ์‹์ด ๋งˆ์ง€๋ง‰ ์™„๋ฃŒ ์Šคํ…์—์„œ ํ•œ ๋ฒˆ๋งŒ ์ผ์–ด๋‚˜๋„๋ก ๋ช…์„ธ๊ฐ€ ๋ณ€๊ฒฝ๋  ์˜ˆ์ •์ด๊ธฐ์— ์Šคํ…๊ฐ„์˜ ํผ ๋ฐ์ดํ„ฐ์˜ ์ƒํƒœ ๊ณต์œ ๊ฐ€ ํ•„์š”ํ•ด์กŒ์–ด์š”.

๊ทธ๋ž˜์„œ react-hook-form ์œผ๋กœ ํผ ๋ฐ์ดํ„ฐ๋ฅผ ๊ด€๋ฆฌํ•˜๊ณ , ์ƒ์œ„์˜ FormProvider ์—์„œ ๋ฟŒ๋ ค์ฃผ๋Š” ๋ฐฉ์‹์œผ๋กœ ๋ณ€๊ฒฝํ–ˆ์–ด์š”.

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

๋งˆ์ด ํŽ˜์ด์ง€ ์„ค๊ณ„ ํ™”๋ฉด

image

์ฃผ๋กœ ์ƒํƒœ ๊ด€๋ฆฌ ๋ฐ ์ƒํƒœ ๊ณต์œ ์— ๋Œ€ํ•œ ๊ณ ๋ฏผ์ด ๋“ค์—ˆ๋Š”๋ฐ.. @seokzin ๋‹˜! ํ˜น์‹œ ์ฝ”๋“œ๋ฆฌ๋ทฐ๋ฅผ ์š”์ฒญ๋“œ๋ ค๋„ ๊ดœ์ฐฎ์„๊นŒ์š”??

๐Ÿ‘ฉโ€๐Ÿ’ป ๊ถ๊ธˆ ์‚ฌํ•ญ

react-hook-form vs zustand

์Šคํ… ๊ฐ„ ํผ ์ƒํƒœ๋ฅผ ๊ณต์œ ํ•ด์•ผ ํ•˜๋Š”๋ฐ.. ํ˜„์—…์—์„œ ์ด๋Ÿฐ ์ƒํ™ฉ์— ๋ณดํ†ต ์–ด๋–ค ๋ฐฉ์‹์„ ์ฑ„ํƒํ•˜์‹ค์ง€ ๊ถ๊ธˆํ•ด์š”.

์ €๋Š” ๊ฐ ์Šคํ…์—์„œ ์ง€์—ญ์ ์œผ๋กœ ๋‹ค๋ค„์ง€๋˜ ํผ ๊ด€๋ จ ์ƒํƒœ๋ฅผ ์–ด๋–ป๊ฒŒ ์ „์—ญ์ ์œผ๋กœ ๊ด€๋ฆฌํ•  ๊ฒƒ์ธ์ง€๋ฅผ ๊ณ ๋ฏผํ–ˆ๋Š”๋ฐ์š”.. ์ƒ๊ฐํ•ด ๋ณธ ๊ฒฐ๊ณผ 2๊ฐ€์ง€๋กœ ์ถ”๋ ค๋ณผ ์ˆ˜ ์žˆ์—ˆ์–ด์š”.

  1. ์ƒ์œ„ ์ปดํฌ๋„ŒํŠธ์—์„œ react-hook-form์„ Provider๋กœ ๋ฟŒ๋ฆฌ๋Š” ๋ฐฉ๋ฒ• (์ƒ์œ„ ์ปดํฌ๋„ŒํŠธ์— ์ƒํƒœ๋ฅผ ์œ„์ž„)
  2. Zustand๊ฐ™์€ ์™ธ๋ถ€ ์Šคํ† ์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ• (๋ฆฌ์•กํŠธ ๋ฐ”๊นฅ ์˜์—ญ์œผ๋กœ ์ƒํƒœ๋ฅผ ์œ„์ž„)

๊ฐ๊ฐ์„ ์„ ํƒํ–ˆ์„ ๋•Œ ์žฅ๋‹จ์ ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋Š”๋ฐ์š”:

react-hook-form

  • ์žฅ์ : ํผ์„ ๋‹ค๋ฃจ๋Š” ๋ฐ ํ•„์š”ํ•œ ๊ธฐ๋ณธ์ ์ธ ๋กœ์ง์„ ์ž‘์„ฑํ•˜์ง€ ์•Š์•„๋„ ๋˜๊ณ , ํผ ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฅผ ์†์‰ฝ๊ฒŒ ํ•  ์ˆ˜ ์žˆ์Œ. (zod์™€ ๊ฐ™์€ ์œ ํšจ์„ฑ ๊ฒ€์ฆ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€์˜ ๊ฐ„ํŽธํ•œ ๊ฒฐํ•ฉ)
  • ๋‹จ์ : FormProvider๋กœ ํ•˜์œ„ ํŠธ๋ฆฌ์— ๊ณต์œ ํ•˜๋Š” ํ˜•ํƒœ๋กœ ์ž‘์„ฑํ•ด์•ผ ํ•˜๋Š”๋ฐ, selector์˜ ๊ฐœ๋…์ด ์—†๋‹ค ๋ณด๋‹ˆ watch๋กœ ์ƒํƒœ๋ฅผ ๊ตฌ๋…ํ•˜๋Š” ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์žˆ๋‹ค๋ฉด ๊ทธ ๊ฐ’์ด ๋ณ€๊ฒฝ๋  ๋•Œ FormProvider ํ•˜์œ„์˜ ๋ชจ๋“  ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ฆฌ๋ Œ๋”๋ง ๋จ.
    ํ›…ํผ ๋ฆฌ๋ Œ๋”๋ง

zustand

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

๊ฒฐ๊ตญ์—๋Š” react-hook-form ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉํ–ฅ์œผ๋กœ ๊ตฌํ˜„ํ•˜๊ฒŒ ๋˜์—ˆ๋Š”๋ฐ, ์‚ฌ์‹ค HTML์˜ ์ „ํ†ต์ ์ธ input์ด ์•„๋‹Œ ์š”์†Œ๋„ ์กด์žฌํ•ด์„œ setValue๋กœ imperativeํ•˜๊ฒŒ ๊ฐ’์„ ๋ณ€๊ฒฝํ•ด์•ผ ํ•˜๊ธด ํ•˜์ง€๋งŒ, ์ฃผ ๊ด€์‹ฌ์‚ฌ๊ฐ€ ์‚ฌ์šฉ์ž์˜ ์ž…๋ ฅ์„ ๋ฐ›๋Š” ํผ์— ๊ฐ€๊น๋‹ค๋Š” ์ƒ๊ฐ ๋•Œ๋ฌธ์ด์—ˆ์–ด์š”. (์‚ฌ์šฉ์ž ์ž…๋ ฅ์— ๋Œ€ํ•œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ๋“ฑ ์ƒˆ๋กœ์šด ์š”๊ตฌ์‚ฌํ•ญ์ด ๋“ค์–ด์™€๋„ ๋น ๋ฅด๊ฒŒ ๋Œ€์‘ํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•ด์„œ?)

๊ทธ๋Ÿฐ๋ฐ.. ๊ดœ์ฐฎ์€ ์ ‘๊ทผ์ด์—ˆ์„์ง€? ๋” ์ข‹์€ ๋ฐฉ๋ฒ•์€ ์—†์—ˆ์„์ง€? ๊ถ๊ธˆํ•ด์š”

Compound ํŒจํ„ด

const Page = () => {
  return (
    <Tabs.Root>
      <Tabs.Item>์•„์ดํ…œ 1์€ Tabs.Root์˜ ์ƒํƒœ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด์š”</Tabs.Item>
      <Tabs.Item>์•„์ดํ…œ 2๋Š” Tabs.Root์˜ ์ƒํƒœ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด์š”</Tabs.Item>
    </Tabs.Root>
  );
}

Tabs ์ปดํฌ๋„ŒํŠธ๊ฐ™์ด, ์žฌํ™œ์šฉ๋˜๊ธฐ ์ข‹์€ ์ปดํฌ๋„ŒํŠธ๋ฅผ Headless UI๋กœ ๊ตฌ์„ฑํ•œ๋‹ค๊ณ  ํ•  ๋•Œ ์ƒํƒœ๋ฅผ ์บก์Šํ™”ํ•ด์„œ ์™ธ๋ถ€๋กœ ๋“ค์–ด๋‚ด์ง€ ์•Š์œผ๋ฉด์„œ๋„ ํ•˜์œ„ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ด๋ฅผ ๋ฐ›์•„์„œ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก Context API๋กœ ์˜์กด์„ฑ ์ฃผ์ž…์„ ํ•ด์ฃผ๋Š” ๋ฐฉ์‹์ด ์ž์ฃผ ์‚ฌ์šฉ๋œ๋‹ค๊ณ  ๋“ค์—ˆ๋Š”๋ฐ์š”!

์ด ๊ฒฝ์šฐ์—๋„ Tabs.Root ์ปดํฌ๋„ŒํŠธ์—์„œ ์ฃผ์ž…ํ•œ value ์ค‘์—์„œ ํ•˜๋‚˜๋ผ๋„ ๋ณ€๊ฒฝ๋˜๋ฉด ๋ชจ๋“  ํ•˜์œ„ ํŠธ๋ฆฌ๊ฐ€ ๋ฆฌ๋ Œ๋”๋ง๋˜๊ธฐ ๋•Œ๋ฌธ์—.. ๋ Œ๋”๋ง ์ตœ์ ํ™”๋ฅผ ์–ด๋–ค ๋ฐฉ์‹์œผ๋กœ ํ•˜๋ฉด ์ข‹์„์ง€? ๊ถ๊ธˆํ•ด์š”!

(Tabs.Root ์ปดํฌ๋„ŒํŠธ๋ฅผ ์„ ์–ธํ•˜๋Š” ๊ณณ๋งˆ๋‹ค ์ƒˆ๋กœ์šด ์ƒํƒœ๋ฅผ ๊ฐ–๊ณ  ํ•˜์œ„ ์ž์‹๋“ค์—๊ฒŒ ๋ฟŒ๋ ค์ค˜์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— zustand๊ฐ™์€ ์ „์—ญ ์Šคํ† ์–ด๋ฅผ ํ•˜๋‚˜๋งŒ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ๋Š” ์–ด๋ ค์šธ ๊ฒƒ ๊ฐ™๊ณ .. Tabs.Root๊ฐ€ ์ƒํƒœ๋ฅผ ๊ฐ–๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ•ด์•ผ ํ•  ๊ฒƒ ๊ฐ™์€๋ฐ.. ํ˜น์‹œ https://docs.pmnd.rs/zustand/guides/initialize-state-with-props ์ด๋Ÿฐ ๋ฐฉ์‹์œผ๋กœ selector๋ฅผ ์ง€์›ํ•˜๋Š” ์™ธ๋ถ€ ์Šคํ† ์–ด๋ฅผ ref๋กœ ๋‹ด์•„์„œ ๋ฟŒ๋ฆฌ๋Š” ๋ฐฉ์‹๋„ ์ฃผ๋กœ ์‚ฌ์šฉ๋ ๊นŒ์š”..? ์‚ฌ์šฉํ•ด๋ณด๋‹ˆ ๋ณด์ผ๋Ÿฌ ํ”Œ๋ ˆ์ดํŠธ๊ฐ€ ์ปค์ง€๋Š” ๋Š๋‚Œ๋„ ๋ฐ›์•˜์—ˆ์–ด์„œ..)

๋งˆ๋ฌด๋ฆฌ

๊ฒฐ๋ก ์ ์œผ๋กœ๋Š”.. ์ „์—ญ ์ƒํƒœ ๊ด€๋ฆฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ž˜ ํ™œ์šฉํ•˜๋Š” ๊ฒƒ์ผ์ง€ ๊ถ๊ธˆํ•ด์š”.
API ํ†ต์‹ ์œผ๋กœ ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ์—๋Š” TanStack Query๋ฅผ, ํผ ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•ด์„œ๋Š” react-hook-form์„, Compound ํŒจํ„ด์—์„œ ์˜์กด์„ฑ ์ฃผ์ž…์—๋Š” Context API ๋ฅผ ์‚ฌ์šฉํ•˜๋‹ค๋ณด๋‹ˆ.. ๋Š˜ ํด๋ผ์ด์–ธํŠธ ์‚ฌ์ด๋“œ ์ƒํƒœ ๊ด€๋ฆฌ ๋„๊ตฌ๋ฅผ ํ™œ์šฉํ•ด๋ณด์ž ์‹ถ์–ด๋„ ์ž˜ ๋ชปํ–ˆ์—ˆ๊ฑฐ๋“ ์š”.. ๐Ÿ˜‚

๋˜ํ•œ, ๋™์ผํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€๋ฆฌํ‚ค๋Š” ์ƒํƒœ๋ฅผ ์—ฌ๋Ÿฌ ๊ณณ์— ๋ถ„์‚ฐํ•ด์„œ ๊ด€๋ฆฌํ•˜๋Š” ๋ฐฉ์‹์€ ์–ด๋–จ์ง€..? ๊ถ๊ธˆํ•ด์š”.
(ex. ๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž ์ •๋ณด๊ฐ€ TanStack Query์— ์˜ํ•ด ๊ด€๋ฆฌ๋˜๊ณ  ์žˆ๋Š”๋ฐ, ์ด ๊ฑธ Zustand์™€ ๊ฐ™์€ ๋‹ค๋ฅธ ์Šคํ† ์–ด์— ์ถ”๊ฐ€ ๊ด€๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•)

์ด๋Ÿฐ ๋ฐฉ์‹์ด single source of truth์— ์œ„๋ฐฐ๋˜๋Š” ๊ฑธ์ง€, ์•„๋‹ˆ๋ฉด ๋‚˜๋ฆ„๋Œ€๋กœ ํŽธํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์˜ˆ์‹œ๊ฐ€ ์žˆ์„์ง€ ๊ถ๊ธˆํ•ด์š”!!

@bbearcookie bbearcookie added the ๐Ÿ”จ Refactor ๋ฆฌํŒฉํ† ๋ง ์ž‘์—… label Feb 11, 2024
@bbearcookie bbearcookie self-assigned this Feb 11, 2024
Copy link

github-actions bot commented Feb 11, 2024

๐Ÿš€ Storybook Preview ๋ณด๋Ÿฌ๊ฐ€๊ธฐ: https://65a6c73d536a3c43b7c5c9bb-saqtcazota.chromatic.com/
๐Ÿš€ React Preview ๋ณด๋Ÿฌ๊ฐ€๊ธฐ: https://dnd-10th-4-frontend-kni5td9nf-bbearcookie.vercel.app

Comment on lines 60 to 62
year: '' as unknown as number,
month: '' as unknown as number,
day: '' as unknown as number,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด ๋ถ€๋ถ„์€ react-hook-form์„ ์ œ์–ด ์ปดํฌ๋„ŒํŠธ ๋ฐฉ์‹์œผ๋กœ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ์—๋Š” ๋ฐ˜๋“œ์‹œ defaultValue๊ฐ€ ๋“ค์–ด๊ฐ€์•ผ ํ•ด์„œ ์ž‘์„ฑํ•œ ๋ถ€๋ถ„์ธ๋ฐ์š”,
submit ๋™์ž‘์—์„œ์˜ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ๋กœ์ง์€ zod ์Šคํ‚ค๋งˆ๋Œ€๋กœ ๋™์ž‘ํ•˜๊ณ  ์‹ถ์€๋ฐ, ์‚ฌ์šฉ์ž๊ฐ€ Input์„ ๋ดค์„ ๋•Œ ๊ธฐ๋ณธ ๊ฐ’์€ ๋น„์–ด์žˆ๋„๋ก ํ•˜๊ณ  ์‹ถ์–ด์„œ ์ž‘์„ฑํ•œ ๋ถ€๋ถ„์ž…๋‹ˆ๋‹ค.. (ํƒ€์ž…์ด ์›๋ž˜ number์—ฌ์•ผ ํ•˜๋Š”๋ฐ, 0์œผ๋กœ ํ•˜๋ฉด Input์— ๊ธฐ๋ณธ ๊ฐ’ 0์ด ๋“ค์–ด๊ฐ€ ์žˆ๋Š” ๋ฌธ์ œ)

์ด ๋ถ€๋ถ„์—์„œ ๋“œ๋Š” ๊ณ ๋ฏผ์ด defaultValue ๊ฐ’์˜ ํƒ€์ž…์€ zod ์Šคํ‚ค๋งˆ์™€๋Š” ๋‹ค๋ฅด๊ฒŒ ํ•˜๊ณ  ์‹ถ์€๋ฐ ๋ฐฉ๋ฒ•์ด ์žˆ์„์ง€? ๊ณ ๋ฏผ๋˜์—ˆ์–ด์š”

Copy link
Member

@seokzin seokzin Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3

๊ทธ๋Ÿฐ ๊ณ ๋ฏผ์ด๋ผ๋ฉด ํƒ€์ž… ๋‹จ์–ธ์„ ํ™œ์šฉํ•˜์ง€ ์•Š๋Š” ์กฐ๊ธˆ ๋” ์ข‹์€ ํ•ด๊ฒฐ์ฑ…์ด ์žˆ๊ฒ ๋„ค์š”.
ํŠนํžˆ as unknown์€ TS๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ๋„ raw ๋ฐ์ดํ„ฐ์˜ ํƒ€์ž… ํŒŒ์•…์ด ์–ด๋ ค์šธ ๋•Œ ์ •๋ง ์ตœํ›„์˜ ์ˆ˜๋‹จ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ทธ๋Ÿฐ ํ…Œํฌ๋‹‰์ด๋‹ˆ๊นŒ์š”.

์ƒํ›ˆ๋‹˜์ด ๊ฐ€์ง„ ๋™์ผํ•œ ์ƒํ™ฉ์— ๋Œ€ํ•ด discussion์ด ์žˆ๋Š”๋ฐ

useForm<{ price: number | string }, void, { price: number }>

์ œ๋„ค๋ฆญ ์œ ๋‹ˆ์˜จ์„ ํ™œ์šฉํ•˜๊ณ  3๋ฒˆ์งธ ์ธ์ž๋ฅผ ํ†ตํ•ด submit๋˜๋Š” ๊ฐ’์„ ๋ณ€ํ˜•ํ•˜๋Š” ์•„์ด๋””์–ด๋„ ์ข‹๋‹ค๊ณ  ์ƒ๊ฐ์ด ๋“ค์–ด์š”.
์ €๋Š” ์ง์ ‘ ํŠธ๋ผ์ด ํ•˜์ง„ ๋ชปํ–ˆ์ง€๋งŒ ์ด๊ฑฐ ํ•œ๋ฒˆ ์ฐธ๊ณ ํ•ด๋ณด์„ธ์š”!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ—‰.. ์ œ๋„ค๋ฆญ ์ธ์ž๋ฅผ ์ „๋‹ฌํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ์—ˆ๊ตฐ์š”.. ๋””์Šค์ปค์…˜ ๋งํฌ๊นŒ์ง€.. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!!

Copy link
Member

@seokzin seokzin Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•—ใ…Žใ…Ž ์˜๋ฆฌ์˜๋ฆฌ,, ์ € ์†”๋ฃจ์…˜์€ ์ œ๋„ค๋ฆญ ๋ง๊ณ  ์œ ๋‹ˆ์˜จ ํƒ€์ž… ์–˜๊ธฐ์˜€๋„ค์š”~~

Comment on lines +51 to +58
onChange={async (e) => {
e.target.value = clampValue(
e.target.value,
formLiteral.year.max,
);
field.onChange(e);
trigger('birthday.year');
}}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RHF์˜ onChange ์ฝœ๋ฐฑ์ด ๋™์ž‘ํ•˜๊ธฐ ์ „์— ๋ฏธ๋ฆฌ intercept ๋™์ž‘์„ ๋ถ€์—ฌํ•˜๊ธฐ ์œ„ํ•ด์„œ(Input์—์„œ ์ˆซ์ž๋งŒ ํ•„ํ„ฐ๋งํ•˜๋Š” ๋กœ์ง) Controller๋กœ ์ œ์–ด ์ปดํฌ๋„ŒํŠธ ๋ฐฉ์‹์„ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as unknwon as ๋ฅผ ์‚ฌ์šฉํ•œ default value ๋กœ์ง์ด ํ•ด๊ฒฐ๋œ๋‹ค๋ฉด ์ด ๋ถ€๋ถ„๋„ ์ถ”ํ›„์— ๊ฐœ์„ ๋  ์ˆ˜ ์žˆ๊ฒ ๋„ค์š”!

Copy link
Member

@seokzin seokzin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ž˜ ๋ดค์Šต๋‹ˆ๋‹ค!
๋ฆฌ๋ทฐ ์š”์ฒญ ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ด์š”.

์ฝ”๋ฉ˜ํŠธ ๋‹ฌ๋ฉด์„œ๋„ ๋ช…์พŒํ•œ ๋‹ต๋ณ€์ด ์•„๋‹Œ ๊ฒƒ ๊ฐ™์•„ ๊ฐœ์ธ์ ์ธ ์•„์‰ฌ์›€์ด ์žˆ๋Š”๋ฐ
์˜๊ฒฌ์„ ๊ฐ€๋ณ๊ฒŒ ์ฐธ๊ณ ๋งŒ ํ•ด์ฃผ์„ธ์š” ใ…Žใ…Ž ์ œ๊ฐ€ ๋ฐ˜๋“œ์‹œ ์˜ณ์ง€๋Š” ์•Š์•„์š”!!
๊ถ๊ธˆํ•œ ์ ์ด ์žˆ๋‹ค๋ฉด ์žฌ๋Œ“๊ธ€์ด๋‚˜ ์Šฌ๋ž™์œผ๋กœ ํŽธํ•˜๊ฒŒ ์งˆ๋ฌธ ์ฃผ์„ธ์š”~!

Copy link
Member

@seokzin seokzin Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ฒฐ๊ตญ์—๋Š” react-hook-form ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉํ–ฅ์œผ๋กœ ๊ตฌํ˜„ํ•˜๊ฒŒ ๋˜์—ˆ๋Š”๋ฐ, ์‚ฌ์‹ค HTML์˜ ์ „ํ†ต์ ์ธ input์ด ์•„๋‹Œ ์š”์†Œ๋„ ์กด์žฌํ•ด์„œ setValue๋กœ imperativeํ•˜๊ฒŒ ๊ฐ’์„ ๋ณ€๊ฒฝํ•ด์•ผ ํ•˜๊ธด ํ•˜์ง€๋งŒ, ์ฃผ ๊ด€์‹ฌ์‚ฌ๊ฐ€ ์‚ฌ์šฉ์ž์˜ ์ž…๋ ฅ์„ ๋ฐ›๋Š” ํผ์— ๊ฐ€๊น๋‹ค๋Š” ์ƒ๊ฐ ๋•Œ๋ฌธ์ด์—ˆ์–ด์š”. (์‚ฌ์šฉ์ž ์ž…๋ ฅ์— ๋Œ€ํ•œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ๋“ฑ ์ƒˆ๋กœ์šด ์š”๊ตฌ์‚ฌํ•ญ์ด ๋“ค์–ด์™€๋„ ๋น ๋ฅด๊ฒŒ ๋Œ€์‘ํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•ด์„œ?)

๋„ค zustand๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์ดˆ๊ธฐ ์ƒํƒœ๋ฅผ ๊ฐœ์„ ํ•œ ํ•ด๊ฒฐ์ฑ…์ด ๋  ์ˆ˜ ์žˆ์ง€๋งŒ
์ง€๊ธˆ์ฒ˜๋Ÿผ form๋งŒ์„ ์ œ์–ดํ•˜๋Š” ํ˜„์žฌ์˜ ํ™˜๊ฒฝ์—์„œ๋Š” react-hook-form์ด ๋” ์ ํ•ฉํ•˜๋„ค์š”.
(= hook form์„ ๊ธฐ๋ฐ˜์œผ๋กœ ๋ฆฌ๋ Œ๋”๋ง์„ ์ตœ์ ํ™”๋ฅผ ๊ณ ๋ฏผํ•˜๋Š” ๋ฐฉํ–ฅ์ด ๋” ์ ํ•ฉํ•˜๋‹ค)
๊ทธ๋ž˜์„œ react-hook-form์œผ๋กœ ์ตœ์ข… ๊ฒฐ์ •ํ•œ ๊ฒƒ์€ ์ข‹์€ ์„ ํƒ์ด์—์š”

๋‹ค๋งŒ input์ด ์•„๋‹Œ ์š”์†Œ๋„ ์กด์žฌ๊ฐ€ ์ •ํ™•ํžˆ ์–ด๋–ค ์ผ€์ด์Šค์ผ๊นŒ ๊ถ๊ธˆํ•ด์ง€๋Š”๋ฐ
ํ˜„์žฌ์˜ ๋””์ž์ธ ๊ฐ€์ด๋“œ๋กœ ๋ดค์„ ๋–„๋Š”
์ œ๊ณต๋˜๋Š” UI๋งŒ ๋‹ค๋ฅผ ๋ฟ, radio, checkbox์˜ ๊ฐœ๋…์€ ๊ฐ€์ง€๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์—
๋””์ž์ธ์‹œ์Šคํ…œ ์ƒ์—์„œ ์ถฉ๋ถ„ํžˆ 'input ํƒœ๊ทธ'๋ฅผ ์ค‘์‹ฌ์œผ๋กœ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๊ฒ ๋‹ค๋Š” ์ƒ๊ฐ์€ ๋“ค์—ˆ์–ด์š”!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ทธ๋ ‡๋‹ค๋ฉด, react-hook-form์˜ ๋ Œ๋”๋ง ์ตœ์ ํ™”๊ฐ€ ๊ด€๊ฑด์ธ๋ฐ,
์ง€๊ธˆ ์ƒํ›ˆ๋‹˜์ด ์ง๋ฉดํ•œ ์ด์Šˆ๋Š” react-hook-form์„ ๋„์ž…ํ•˜๋Š” ๊ฐœ๋ฐœ์ž๋“ค์ด ํ•œ๋ฒˆ์ฏค์€ ๊ฒช์—ˆ์„ ๋ณดํŽธ์  ์ด์Šˆ๋กœ ๋ณด์—ฌ์„œ ์ถฉ๋ถ„ํžˆ ์†”๋ฃจ์…˜์ด ๋งŽ๊ฒ ๋‹ค๋Š” ์ƒ๊ฐ์€ ๋“ค์—ˆ์–ด์š”!

ํ˜น์‹œ useWatch๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํŠธ๋Ÿฌ๋ธ” ์ŠˆํŒ… ํ•ด๋ณด์…จ์„๊นŒ์š”?
watch์˜ ์ „์ฒด ๋ Œ๋”๋ง ๋‹จ์ ์„ ๋ณด์™„ํ•œ API ์ธ๋ฐ ์ฐธ๊ณ ๋กœ ์ €๋Š” ์‹ค์ œ ์‚ฌ์šฉ ๊ฒฝํ—˜์ด ์—†์–ด์„œ ํ™•๋‹ต์œผ๋กœ๋Š” ๋ชป ๋“œ๋ฆฐ๋‹ค๋Š” ์  ๐Ÿ˜ญ

Copy link
Member

@seokzin seokzin Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tabs -> compound ํŒจํ„ด

์ด ๊ฒฝ์šฐ์—๋„ Tabs.Root ์ปดํฌ๋„ŒํŠธ์—์„œ ์ฃผ์ž…ํ•œ value ์ค‘์—์„œ ํ•˜๋‚˜๋ผ๋„ ๋ณ€๊ฒฝ๋˜๋ฉด ๋ชจ๋“  ํ•˜์œ„ ํŠธ๋ฆฌ๊ฐ€ ๋ฆฌ๋ Œ๋”๋ง๋˜๊ธฐ ๋•Œ๋ฌธ์—.. ๋ Œ๋”๋ง ์ตœ์ ํ™”๋ฅผ ์–ด๋–ค ๋ฐฉ์‹์œผ๋กœ ํ•˜๋ฉด ์ข‹์„์ง€? ๊ถ๊ธˆํ•ด์š”!

Tabs ๊ฐ™์ด atomic ๋ณด๋‹ค๋Š” molecule์— ๊ฐ€๊นŒ์šด ๋ณต์žกํ•œ ์ปดํฌ๋„ŒํŠธ๋Š” ์ƒํ›ˆ๋‹˜ ๋ง์”€๋Œ€๋กœ Context API๋ฅผ ํ†ตํ•ด state๋ฅผ component scope๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹์€ ํ…Œํฌ๋‹‰์ด์ฃ !

๋‹ค๋งŒ 'value ์ค‘์—์„œ ํ•˜๋‚˜๋ผ๋„ ๋ณ€๊ฒฝ๋˜๋ฉด ๋ชจ๋“  ํ•˜์œ„ ํŠธ๋ฆฌ๊ฐ€ ๋ฆฌ๋ Œ๋”๋ง๋˜๊ธฐ ๋•Œ๋ฌธ์—' ๋ผ๋Š” ์ด์Šˆ๊ฐ€ ์ž์„ธํžˆ ๊ถ๊ธˆํ•ด์ ธ์š”.

๋ณดํŽธ์ ์ธ Tabs๋ผ๋ฉด ์ตœ์ดˆ ๋ Œ๋”๋ง๋œ Tab label์€ ๋ถˆ๋ณ€ํ•  ๊ฒƒ์ด๊ณ ,
Tab์„ ๋ณ€๊ฒฝํ–ˆ์„ ๋•Œ content๊ฐ€ ๋ฆฌ๋ Œ๋”๋ง ๋˜๋Š” ๊ฒƒ์€ ๋ถˆ๊ฐ€ํ”ผํ•œ ๋ Œ๋”๋ง์ผํ…๋ฐ
๊ทธ ์™ธ์— ๋ Œ๋”๋ง ์ตœ์ ํ™”๋ฅผ ํ•œ๋‹ค๋ฉด ์–ด๋Š ๋ถ€๋ถ„์ด ์žˆ์„๊นŒ์š”?

Copy link
Member

@seokzin seokzin Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tabs.Root ์ปดํฌ๋„ŒํŠธ๋ฅผ ์„ ์–ธํ•˜๋Š” ๊ณณ๋งˆ๋‹ค ์ƒˆ๋กœ์šด ์ƒํƒœ๋ฅผ ๊ฐ–๊ณ  ํ•˜์œ„ ์ž์‹๋“ค์—๊ฒŒ ๋ฟŒ๋ ค์ค˜์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— zustand๊ฐ™์€ ์ „์—ญ ์Šคํ† ์–ด๋ฅผ ํ•˜๋‚˜๋งŒ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ๋Š” ์–ด๋ ค์šธ ๊ฒƒ ๊ฐ™๊ณ .. ์ด๋Ÿฐ ๋ฐฉ์‹์œผ๋กœ selector๋ฅผ ์ง€์›ํ•˜๋Š” ์™ธ๋ถ€ ์Šคํ† ์–ด๋ฅผ ref๋กœ ๋‹ด์•„์„œ ๋ฟŒ๋ฆฌ๋Š” ๋ฐฉ์‹๋„ ์ฃผ๋กœ ์‚ฌ์šฉ๋ ๊นŒ์š”..?

๋ณต์žกํ•œ ์„œ๋น„์Šค์—์„  Tabs๋ฅผ ๋ฃจํŠธ์—์„œ ์กฐ๊ฑด๋ถ€ ๋ Œ๋”๋ง ํ•˜๋ฉด
์˜คํžˆ๋ ค ์กฐ๊ฑด ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฒƒ์ด ๋ถˆํŽธํ•˜๊ณ  ์‚ฌ์ด๋“œ ์ดํŽ™ํŠธ๊ฐ€ ํฌ๊ฒŒ ๋ผ์š”.
๊ทธ๋ž˜์„œ ์ €๋Š” ๊ฐœ๋ณ„ ํŽ˜์ด์ง€ ๋‹จ์—์„œ Tabs๋ฅผ ๋งค๋ฒˆ import ํ•˜๋Š” ๋ฐฉ์‹์„ ์„ ํƒํ–ˆ์–ด์„œ, store์— ๋Œ€ํ•œ ๋‹ˆ์ฆˆ๋Š” ๋‹คํ–‰ํžˆ ์—†์—ˆ์–ด์š”.
(์ €๋Š” ๋ฃจํŠธ์—์„œ ๊ด€๋ฆฌํ•˜๋Š” Toast, Popup, Header ๋“ฑ์—์„œ store๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์ฃ !)

ํ˜น์‹œ ํ˜„์žฌ ์„œ๋น„์Šค๋Š” Tabs๋ฅผ Root์—์„œ ์ทจ๊ธ‰ํ•˜๋‚˜์š”? ๊ทธ๋ ‡๋‹ค๋ฉด ์ „์—ญ store์— ๋Œ€ํ•œ ๋‹ˆ์ฆˆ๊ฐ€ ์žˆ์„ ๊ฒƒ์ด๊ณ , ์ €๋Š” ์ด๋Ÿฐ ui๋ฅผ ์œ„ํ•œ store๋ฅผ ๊ณผ๊ฐํžˆ ๋งŒ๋“ค์–ด์š”. (์–ด์ฐจํ”ผ store๋“ค์„ ๋‹จ์ผ ์ฑ…์ž„์— ๋งž๊ฒŒ ๋‚˜๋ˆ„๋ฉด ํŒŒ์ผ์€ ์ปค์งˆ ์ˆ˜ ๋ฐ–์— ์—†์ง€๋งŒ, ์ด๋ฅผ ํด๋” ๊ตฌ์กฐ๋กœ ์ž˜ ์ •๋ฆฌํ•œ๋‹ค๋ฉด ์‚ฌ์šฉ์— ๋ถˆํŽธํ•จ์€ ํฌ๊ฒŒ ์—†์œผ๋ฏ€๋กœ)

+) ๋‹ค๋งŒ ์ €๋Š” root ๋‹จ์—์„œ ui store๋ฅผ ์‚ฌ์šฉํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— provider์˜ ๋‹ˆ์ฆˆ๊นŒ์ง€๋Š” ์—†์—ˆ์–ด์š”!
ref & provider๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ ํ•œ ๋‹จ๊ณ„ ๋” ๊ณ ๋ฏผ์ด ๋˜๊ฒ ์ง€๋งŒ, ์ œ๊ฐ€ ์ƒ๊ฐํ•˜๋Š” ๋””์ž์ธ์‹œ์Šคํ…œ์˜ Tabs๋Š” store๊ฐ€ ๋ถˆํ•„์š”ํ•œ ์„ค๊ณ„ ๋ฐฉ์‹์ด ๋” ๋ณดํŽธ์ ์ด๋ผ ์ƒ๊ฐํ•ด์„œ, ์ด ๋ถ€๋ถ„์— ๋Œ€ํ•ด ํฐ ๊ณ ๋ฏผ์„ ์•ˆ ํ•ด๋ดค๋˜ ๊ฒƒ ๊ฐ™์•„์š”.

Copy link
Member

@seokzin seokzin Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋งˆ๋ฌด๋ฆฌ

์ „์—ญ ์ƒํƒœ ๊ด€๋ฆฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ž˜ ํ™œ์šฉํ•˜๋Š” ๊ฒƒ์ผ์ง€ ๊ถ๊ธˆํ•ด์š”

์ „์—ญ ์ƒํƒœ๋Š” '์—ฌ๋Ÿฌ ํ•ด๊ฒฐ์ฑ…์„ ๊ณ ๋ฏผํ•œ ๋’ค ๊ทธ๋Ÿผ์—๋„ ๋ถˆ๊ฐ€ํ”ผํ•  ๋•Œ ๋„์ž…'ํ•œ๋‹ค๋ฉด ๋Œ€๋ถ€๋ถ„์€ ์ข‹์€ ๊ฒฐ์ •์ด๋”๋ผ๊ตฌ์š”.
(๊ฐœ์ธ์ ์œผ๋กœ prop drilling์„ ์ง€์–‘ํ•˜๋Š” ์„ฑํ–ฅ์ด ์žˆ์–ด์„œ, ์›ฌ๋งŒํ•˜๋ฉด store๋‚˜ context๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ํŽธ!)

์„œ๋ฒ„ ๊ด€๋ จ ๋กœ์ง์€ Tanstack query๋ฅผ ํ†ตํ•ด ์ฒ ์ €ํžˆ ์›๊ฒฉ์œผ๋กœ ์ƒํƒœ ๊ด€๋ฆฌํ•˜๋Š” ๊ฒƒ์€ ์š”์ฆ˜ ํŠธ๋ Œ๋“œ์— ์ ํ•ฉํ•ด์š”.

form ๊ด€๋ จ ๋ฐ์ดํ„ฐ๋Š” react-hook-form + provider๋ฅผ ์‚ฌ์šฉํ•œ ๊ฒƒ ๋˜ํ•œ react-hook-form์˜ ์ž์ฒด ๊ธฐ๋Šฅ์„ ํ™œ์šฉํ•˜๊ธฐ ์šฉ์ดํ•˜๊ณ , ์ „์—ญ ์ƒํƒœ๊ด€๋ฆฌ์˜ ๋‹จ์ ์„ ๋ณด์™„ํ•  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ์ข‹์€ ์„ ํƒ์ด์—์š”.

Compound UI์—์„œ context ์‚ฌ์šฉ ๋˜ํ•œ ์ ํ•ฉํ•ด์š”. UI์— ์ „์—ญ ์ƒํƒœ๋ฅผ ๋„์ž…ํ•˜์ง€ ์•Š์œผ๋ฉด, ์ƒํƒœ ์˜์กด์„ฑ์ด ์—†์–ด์ ธ ๋””์ž์ธ์‹œ์Šคํ…œ์˜ ์žฌ์‚ฌ์šฉ์„ฑ์„ ๊ทน๋Œ€ํ™” ํ•  ์ˆ˜ ์žˆ๊ฑฐ๋“ ์š”.

๊ฒฐ๋ก ์ ์œผ๋กœ ์ „์—ญ ์ƒํƒœ๊ด€๋ฆฌ๋ฅผ ๋„์ž…ํ•˜๋Š” ๋Œ€๋ถ€๋ถ„์˜ ๊ณ ๋ฏผ์€ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์„ ๊ฐœ๋ฐœํ•˜๋ฉด์„œ ๋งŽ์ด ํ•˜๊ฒŒ ๋˜์ฃ . ์œ„ ์ผ€์ด์Šค๋“ค์ฒ˜๋Ÿผ ํŠน์ • scope(form, ui)์—์„œ์˜ ์ƒํƒœ ๊ด€๋ฆฌ๋‚˜, ์„œ๋ฒ„์™€์˜ ์ƒํƒœ ๊ด€๋ฆฌ๋Š” ์ƒํ›ˆ๋‹˜์˜ ์ƒ๊ฐ์ด ๋” ์ ํ•ฉํ•˜๋ฏ€๋กœ ์ถ”ํ›„ ์„œ๋น„์Šค ๊ณ ๋„ํ™” ํ•˜๋ฉด์„œ ์ „์—ญ ์ƒํƒœ๋“ค ๋งŒ๋“ค๋ฉด ๋  ๊ฒƒ ๊ฐ™์•„์š”.

Copy link
Member Author

@bbearcookie bbearcookie Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋””์ž์ธ์‹œ์Šคํ…œ ์ƒ์—์„œ ์ถฉ๋ถ„ํžˆ 'input ํƒœ๊ทธ'๋ฅผ ์ค‘์‹ฌ์œผ๋กœ ๊ตฌํ˜„

์•—.. UI๊ฐ€ ๋‹ฌ๋ผ์„œ Input์ด๋ผ๋Š” ์ƒ๊ฐ์„ ๋ชปํ–ˆ์—ˆ๋Š”๋ฐ
๋™์ž‘์˜ ๊ด€์ ์—์„œ ์ถฉ๋ถ„ํžˆ input์˜ radio, checkbox๋กœ๋„ ๊ตฌํ˜„์ด ๊ฐ€๋Šฅํ•˜๊ฒ ๊ตฐ์š” ๐Ÿ˜‚

useWatch๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํŠธ๋Ÿฌ๋ธ” ์ŠˆํŒ…

useWatch์™€ watch์˜ ์ฐจ์ด์ ์ด ๋‹จ์ˆœํžˆ control ๊ฐ์ฒด๋ฅผ ์ธ์ž๋กœ ๋ฐ›๋Š”์ง€์˜ ์ฐจ์ด์ธ์ค„ ์•Œ์•˜๋Š”๋ฐ..
๋ Œ๋”๋ง ์ตœ์ ํ™”๋ผ๋Š” ์ค‘์š”ํ•œ ํฌ์ธํŠธ์—์„œ ์ฐจ์ด๊ฐ€ ์žˆ์—ˆ๊ตฐ์š”!! ํ…Œ์ŠคํŠธ ํ•ด๋ณด๋‹ˆ ์ž˜ ๋˜๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!!

useWatch

Tab์„ ๋ณ€๊ฒฝํ–ˆ์„ ๋•Œ content๊ฐ€ ๋ฆฌ๋ Œ๋”๋ง ๋˜๋Š” ๊ฒƒ์€ ๋ถˆ๊ฐ€ํ”ผํ•œ ๋ Œ๋”๋ง

์•„ํ•˜.. Tab์ด ๋ณ€๊ฒฝ๋˜๋ฉด Tabs์˜ Content๊ฐ€ ๋ฆฌ๋ Œ๋”๋ง ๋˜๋Š” ๊ฒƒ์ด ๋งž๊ธฐ ๋•Œ๋ฌธ์— ์ตœ์ ํ™”๋ฅผ ๊ณ ๋ คํ•ด๋ณผ ์ˆ˜ ์žˆ๋Š” ๋ถ€๋ถ„์ด ์—†๊ฒ ๊ตฐ์š”!!
์‚ฌ์‹ค ์˜ˆ์‹œ์™€ ์œ ์‚ฌํ•œ ์ƒํ™ฉ์ด Funnel ์Šคํ…์„ ์กฐ์ž‘ํ•˜๋Š” ํ•ธ๋“ค๋Ÿฌ (toNext, toPrev) ๋ฅผ ํ•˜์œ„ ํŠธ๋ฆฌ์— ๊ณต์œ ํ•˜๊ณ  ์‹ถ์—ˆ์„ ๋•Œ ์˜€๋Š”๋ฐ์š”..

๋‹น์‹œ ๊ฒฐ๋ก ์€ ์‚ฌ์‹ค ํ•ธ๋“ค๋Ÿฌ ํ•จ์ˆ˜์˜ ๊ฐ’์ด ์ตœ์ดˆ ๋งˆ์šดํŠธ ์‹œ์  ์ดํ›„์—๋Š” ๋ณ€๊ฒฝ๋˜์ง€ ์•Š๊ธฐ๋„ ํ•˜๊ณ , Provider๊ฐ€ ๊ฐ์‹ธ๊ณ  ์žˆ๋Š” ์Šคํ… ์˜์—ญ์ด ๋ณ€ํ™”๊ฐ€ ์ผ์–ด๋‚˜๋ฉด ์–ด์ฐจํ”ผ ๋‹ค๋ฅธ ์Šคํ…์„ ๋ณด์—ฌ ์ค˜์•ผ ํ•˜๋Š” ๋“ฑ Content๊ฐ€ ๋ฆฌ๋ Œ๋”๋ง ๋˜๋Š” ๊ฒƒ์ด ๋งž๊ธฐ ๋•Œ๋ฌธ์— ์ƒ์œ„ ์ปดํฌ๋„ŒํŠธ์˜ Provider์—์„œ Context API๋กœ ๋ฟŒ๋ ค์ฃผ๋Š” ๋ฐฉ์‹์„ ์„ ํƒํ–ˆ์—ˆ๋Š”๋ฐ, ์ด ๊ณผ์ •์— ๋ Œ๋”๋ง ์ตœ์ ํ™”๊ฐ€ ํ•„์š”ํ•˜๋ ค๋‚˜ ์‹ถ์€ ์ƒ๊ฐ์— ๋ง‰์—ฐํ•˜๊ฒŒ ๋– ์˜ค๋ฅธ ๊ณ ๋ฏผ์ด์—ˆ์Šต๋‹ˆ๋‹ค ๐Ÿ˜‚

(์ง€๊ธˆ์€ ํ•ธ๋“ค๋Ÿฌ๋งŒ ๊ณต์œ ํ•˜๊ณ  ์žˆ๊ธฐ์— ๋ฌธ์ œ๋  ๋ถ€๋ถ„์€ ์—†์ง€๋งŒ.. ๋งŒ์•ฝ Compound Pattern์—์„œ ๊ฐ’์ด ์ž์ฃผ ๋ณ€๊ฒฝ๋˜๋Š” state๋ฅผ Provider์—์„œ ๋ฟŒ๋ ค์ค€๋‹ค๋ฉด ๋ Œ๋”๋ง ์ตœ์ ํ™”๊ฐ€ ํ•„์š”ํ•œ ๊ฒฝ์šฐ์—๋Š” ์–ด๋–ป๊ฒŒ ํ•ด๊ฒฐํ• ๊นŒ? ํ•˜๋Š” ๊ณ ๋ฏผ)

์›๋ž˜ ์ƒํƒœ ๊ด€๋ฆฌ ๋ฐ ๋ Œ๋”๋ง ์ตœ์ ํ™”์— ๋Œ€ํ•ด์„œ ๋ง‰์—ฐํ•œ ๊ณ ๋ฏผ์œผ๋กœ๋งŒ ๊ฐ€์ง€๊ณ  ์žˆ์—ˆ๋Š”๋ฐ, ์˜ค๋Š˜ ๋ฆฌ๋ทฐ ํ•ด์ฃผ์‹  ๋•๋ถ„์— ๋ Œ๋”๋ง ์ตœ์ ํ™”๊ฐ€ ์ •๋ง ํ•„์š”ํ•œ ๋ถ€๋ถ„์ผ์ง€, ํ˜น์€ ์ƒํƒœ๊ฐ€ ํŠน์ • scope๋ฅผ ๊ฐ€์ ธ์•ผ ํ•˜๋Š”์ง€ ํ˜น์€ ์•ฑ ์ „์ฒด์—์„œ ํ•˜๋‚˜๋งŒ ์กด์žฌํ•ด๋„ ๋˜๋Š”์ง€ ๋“ฑ์„ ๋จผ์ € ์ƒ๊ฐํ•ด๋ณด๋Š” ๊ฒƒ๋„ ์ข‹๊ฒ ๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ค์—ˆ์–ด์š”!! ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compound, Composition

์ œ๊ฐ€ Compound ํŒจํ„ด๊ณผ, Composition ์ปดํฌ๋„ŒํŠธ์˜ ์ •์˜์—์„œ ํ—ท๊ฐˆ๋ฆฌ๋Š” ๋ถ€๋ถ„์ด ์žˆ๋Š”๋ฐ์š”.. ๐Ÿ˜‚
Compound ํŒจํ„ด์ด Composition ์ปดํฌ๋„ŒํŠธ๋ฅผ ํ™œ์šฉํ•˜๋ฉด์„œ๋„ ์ƒํƒœ๋ฅผ ํ•˜์œ„ ํŠธ๋ฆฌ์— ๊ณต์œ ํ•˜๋Š” ๋” ์ข์€ ์ง‘ํ•ฉ์˜ ๊ฐœ๋…์œผ๋กœ ์ดํ•ดํ•˜๋Š” ๊ฒƒ์ด ๋งž์„๊นŒ์š”??
(Compound ํŒจํ„ด์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” Composition ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉ?)

image

Copy link
Member

@seokzin seokzin Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bbearcookie

compound, composition

์ €๋„ ์ž‘์„ฑํ•˜๊ณ  ๋ณด๋‹ˆ๊นŒ ์ œ๊ฐ€ ์ •์˜ํ•˜๋Š” ๋‘ ๋‹จ์–ด์˜ ๊ฐœ๋…์ด ์ƒํ›ˆ๋‹˜๊ณผ ๋‹ค๋ฅธ ๊ฒƒ์„ ์ธ์ง€ํ–ˆ์–ด์š”.
์ด๊ฑฐ ์งš์–ด์ฃผ์…”์„œ ๋„˜ ๊ฐ์‚ฌํ•ด์š”~!

"Tabs ์ปดํฌ๋„ŒํŠธ๊ฐ™์ด, ์žฌํ™œ์šฉ๋˜๊ธฐ ์ข‹์€ ์ปดํฌ๋„ŒํŠธ๋ฅผ Headless UI๋กœ ๊ตฌ์„ฑํ•œ๋‹ค๊ณ  ํ•  ๋•Œ ์ƒํƒœ๋ฅผ ์บก์Šํ™”ํ•ด์„œ ์™ธ๋ถ€๋กœ ๋“ค์–ด๋‚ด์ง€ ์•Š์œผ๋ฉด์„œ๋„ ํ•˜์œ„ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ด๋ฅผ ๋ฐ›์•„์„œ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก Context API๋กœ ์˜์กด์„ฑ ์ฃผ์ž…์„ ํ•ด์ฃผ๋Š” ๋ฐฉ์‹์ด ์ž์ฃผ ์‚ฌ์šฉ๋œ๋‹ค๊ณ  ๋“ค์—ˆ๋Š”๋ฐ์š”!"

์—ฌ๊ธฐ์„œ '์•„ํ•˜~ ์ปดํฌ๋„ŒํŠธ ๋””์ž์ธ ํŒจํ„ด์ธ compound pattern์„ context API๋ฅผ ํ†ตํ•ด ์„ค๊ณ„' ํ•œ๋‹ค๋Š” ๋ง์ด๊ตฌ๋‚˜
๋ผ๊ณ  ์ƒ๊ฐ ํ–ˆ์—ˆ๊ณ 

const Page = () => {
  return (
    <Tabs.Root>
      <Tabs.Item>์•„์ดํ…œ 1์€ Tabs.Root์˜ ์ƒํƒœ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด์š”</Tabs.Item>
      <Tabs.Item>์•„์ดํ…œ 2๋Š” Tabs.Root์˜ ์ƒํƒœ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด์š”</Tabs.Item>
    </Tabs.Root>
  );
}

๋‹ค์Œ์œผ๋กœ ์ˆ˜๋„ ์ฝ”๋“œ๋กœ? ๋ณด์ด๋Š” ์ด ์˜ˆ์‹œ๋ฅผ ๋ณด์•˜์„ ๋•
'Tabs๋Š” ํ•˜์œ„ ์ปดํฌ๋„ŒํŠธ๋“ค์„ ์กฐ๋ฆฝํ•ด์„œ ๋‹ค์–‘ํ•œ ์ผ€์ด์Šค๋ฅผ ์ •์˜ํ•ด์•ผ ํ•  ๋‹ˆ์ฆˆ๊ฐ€ ์žˆ๋Š” UI๊ฐ€ ์•„๋‹Œ ๊ฒƒ ๊ฐ™์•„
compound pattern + Context API๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ์—๋Š” ์ ํ•ฉํ•˜์ง€ ์•Š๊ฒ ๊ตฐ" ์ด๋ผ๊ณ  ์ƒ๊ฐํ–ˆ๋„ค์š”

composition์€ ๋””์ž์ธ ํŒจํ„ด๋ณด๋‹ค๋Š” '์ปดํฌ๋„ŒํŠธ๋ฅผ ํ•ฉ์„ฑํ•œ๋‹ค'๋Š” ๋” ํฌ๊ด„์ ์ธ ์˜๋ฏธ์— ๊ฐ€๊นŒ์›Œ์„œ
์‚ฌ์‹ค children์œผ๋กœ ReactNode๋ฅผ ๋ฐ›๋Š” ๊ฒƒ์ด๋‚˜ compound pattern ๋“ฑ์€ ๋„“๊ฒŒ ๋ณด๋ฉด ๋‹ค composition์ด ์•„๋‹๊นŒ ์ƒ๊ฐ์ด ๋“ค์–ด์š”.

์ •๋ฆฌํ•˜์ž๋ฉด ์ œ ์˜๋„๋Š”

"Tabs๋Š” Context API๋ฅผ ํ™œ์šฉํ•œ compound pattern์œผ๋กœ ๊ตฌํ˜„ํ•˜๊ธฐ์—๋Š” ์ž˜ ์–ด์šธ๋ฆฌ๋Š” UI๋Š” ์•„๋‹ ๊ฒƒ์œผ๋กœ ๋ณด์—ฌ, ๋‹จ์ˆœํžˆ property๋ฅผ ํ†ตํ•ด component composition ํ•˜์—ฌ๋„ ๊ดœ์ฐฎ๊ฒ ๋‹ค" ๋ผ๋Š” ์˜๋ฏธ์—ˆ์Šต๋‹ˆ๋‹คใ…Žใ…Ž

Copy link
Member

@seokzin seokzin Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compound ํŒจํ„ด์ด Composition ์ปดํฌ๋„ŒํŠธ๋ฅผ ํ™œ์šฉํ•˜๋ฉด์„œ๋„ ์ƒํƒœ๋ฅผ ํ•˜์œ„ ํŠธ๋ฆฌ์— ๊ณต์œ ํ•˜๋Š” ๋” ์ข์€ ์ง‘ํ•ฉ์˜ ๊ฐœ๋…

ํƒ€๋‹นํ•˜์ฃ !

๋‹ค๋งŒ ์ง‘ํ•ฉ์œผ๋กœ ๋น„์œ ํ•œ๊ธฐ์—” ๋‘˜์˜ ์„ฑ๊ฒฉ์ด ๋‹ค๋ฅผ ์ˆ˜ ์žˆ๋‹ค ์ƒ๊ฐํ•ด์„œ
compound pattern์€ ์ปดํฌ๋„ŒํŠธ ๋””์ž์ธ ํŒจํ„ด์— ๊ฐ€๊น๊ณ 
composition์€ ๋„“์€ ์˜๋ฏธ์˜ '์ปดํฌ๋„ŒํŠธ๋ฅผ ํ•ฉ์„ฑํ•œ๋‹ค'๋ผ๋Š” ํ•˜๋‚˜์˜ ๋ฐฉ๋ฒ•๋ก ์œผ๋กœ ๊ตฌ๋ถ„ํ•˜๋Š” ๊ฒƒ๋„ ์ข‹์•„๋ณด์—ฌ์š”~!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•„ํ•˜!! ์™„๋ฒฝํžˆ ์ดํ•ดํ–ˆ์Šต๋‹ˆ๋‹ค ๐Ÿ˜

compound pattern์€ ๋””์ž์ธ ํŒจํ„ด์˜ ์ผ์ข…์ด๊ณ , composition์€ ๊ทธ๋ณด๋‹ค ํ›จ์”ฌ ํฌ๊ด„์ ์ธ ์˜๋ฏธ์˜ ๋ฐฉ๋ฒ•๋ก  ์ค‘ ํ•˜๋‚˜์ธ ๊ฒƒ์ด๊ตฐ์š”!!

Tabs์˜ ์˜ˆ์‹œ์˜ ๊ฒฝ์šฐ์—๋Š” ํ™•์‹คํžˆ ํ•˜์œ„ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์กฐํ•ฉํ•ด์„œ ์ƒํƒœ๋ฅผ ๊ณต์œ ํ•ด์•ผ ํ•  ์ผ€์ด์Šค๊ฐ€ ๋‹ค์–‘ํ•˜์ง€ ์•Š๊ธฐ์— compound ํŒจํ„ด์„ ์ ์šฉํ•˜๊ธฐ์—๋Š” ์ ํ•ฉํ•˜์ง€ ์•Š๊ฒ ๋„ค์š”..

ํ‰์†Œ์— ํ˜ผ๋™๋˜๋˜ ๊ฐœ๋…์ด์—ˆ๋Š”๋ฐ.. ์ƒ์„ธํ•˜๊ฒŒ ์ •๋ฆฌํ•ด์ฃผ์‹  ๋•๋ถ„์— ๋ช…ํ™•ํ•˜๊ฒŒ ์ดํ•ด๊ฐ€ ๋˜์—ˆ์–ด์š”! ์ •๋ง ๋„ˆ๋ฌด๋„ˆ๋ฌด ๊ฐ์‚ฌ๋“œ๋ฆฝ๋‹ˆ๋‹ค!! ๐Ÿ˜Š๐Ÿ‘๐Ÿ‘

Comment on lines 60 to 62
year: '' as unknown as number,
month: '' as unknown as number,
day: '' as unknown as number,
Copy link
Member

@seokzin seokzin Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3

๊ทธ๋Ÿฐ ๊ณ ๋ฏผ์ด๋ผ๋ฉด ํƒ€์ž… ๋‹จ์–ธ์„ ํ™œ์šฉํ•˜์ง€ ์•Š๋Š” ์กฐ๊ธˆ ๋” ์ข‹์€ ํ•ด๊ฒฐ์ฑ…์ด ์žˆ๊ฒ ๋„ค์š”.
ํŠนํžˆ as unknown์€ TS๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ๋„ raw ๋ฐ์ดํ„ฐ์˜ ํƒ€์ž… ํŒŒ์•…์ด ์–ด๋ ค์šธ ๋•Œ ์ •๋ง ์ตœํ›„์˜ ์ˆ˜๋‹จ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ทธ๋Ÿฐ ํ…Œํฌ๋‹‰์ด๋‹ˆ๊นŒ์š”.

์ƒํ›ˆ๋‹˜์ด ๊ฐ€์ง„ ๋™์ผํ•œ ์ƒํ™ฉ์— ๋Œ€ํ•ด discussion์ด ์žˆ๋Š”๋ฐ

useForm<{ price: number | string }, void, { price: number }>

์ œ๋„ค๋ฆญ ์œ ๋‹ˆ์˜จ์„ ํ™œ์šฉํ•˜๊ณ  3๋ฒˆ์งธ ์ธ์ž๋ฅผ ํ†ตํ•ด submit๋˜๋Š” ๊ฐ’์„ ๋ณ€ํ˜•ํ•˜๋Š” ์•„์ด๋””์–ด๋„ ์ข‹๋‹ค๊ณ  ์ƒ๊ฐ์ด ๋“ค์–ด์š”.
์ €๋Š” ์ง์ ‘ ํŠธ๋ผ์ด ํ•˜์ง„ ๋ชปํ–ˆ์ง€๋งŒ ์ด๊ฑฐ ํ•œ๋ฒˆ ์ฐธ๊ณ ํ•ด๋ณด์„ธ์š”!

Comment on lines +51 to +58
onChange={async (e) => {
e.target.value = clampValue(
e.target.value,
formLiteral.year.max,
);
field.onChange(e);
trigger('birthday.year');
}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as unknwon as ๋ฅผ ์‚ฌ์šฉํ•œ default value ๋กœ์ง์ด ํ•ด๊ฒฐ๋œ๋‹ค๋ฉด ์ด ๋ถ€๋ถ„๋„ ์ถ”ํ›„์— ๊ฐœ์„ ๋  ์ˆ˜ ์žˆ๊ฒ ๋„ค์š”!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ˆœ์ˆ˜ํ•œ ํ•จ์ˆ˜๋“ค์ด util๋กœ ์ž˜ ๋ถ„๋ฆฌ๋˜์—ˆ๊ณ 
ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋„ ์ž˜ ๊ฐ–์ถฐ์ ธ ์žˆ์–ด์„œ
์ด๋Ÿฐ ๋ถ€๋ถ„์˜ ๋ฆฌํŒฉํ„ฐ๋ง์€ ์ฐธ ์˜๋ฏธ ์žˆ๋„ค์š” ๐Ÿ‘

@easyhyun00
Copy link
Collaborator

seokzin ๋‹˜์ด ๋„ˆ๋ฌด ์ข‹์€ ๋ฆฌ๋ทฐ๋ฅผ ๋‚จ๊ฒจ์ฃผ์…จ๋„ค์š”..! ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ๐Ÿ‘ ๋ณด๋ฉด์„œ ์ €๋„ ๋งŽ์ด ์•Œ์•„๊ฐ€๊ณ  ๋ฐฐ์›Œ๊ฐ‘๋‹ˆ๋‹ค!

@bbearcookie bbearcookie merged commit 3de2f48 into main Feb 13, 2024
7 checks passed
@bbearcookie bbearcookie deleted the refactor/#95/onboarding-state branch February 13, 2024 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
๐Ÿ”จ Refactor ๋ฆฌํŒฉํ† ๋ง ์ž‘์—…
Projects
None yet
3 participants