#7-0 ๋ค์ด๊ฐ๋ ๋ง
๊ธฐ์กด์ ์์ฑํ ํ์๊ฐ์
ํผ์ ์ ํจ์ฑ ๊ฒ์ฌ๊ธฐ๋ฅ์ ๋ณด์ํ๋ ค๋ ์ฐจ์ react-hook-form์ด ์๋ค๋๊ฑธ ์๊ฒ ๋์๋ค. react-hook-form์ ์ด์ฉํ๋๊ฒ ๊ธฐ์กด ์ฝ๋์ ์๋ ์ค์ผ ์ ์๊ณ , ์ข ๋ ์ ์ง์ฌ์ง ๊ธฐ๋ฅ์ ๋น ๋ฅด๊ฒ ๊ฐ์ ธ๋ค ์ธ ์ ์์๊ฑฐ ๊ฐ์ ํ๋ฒ ์ ์ฉ์์ผ ๋ณด์๋ค.
#7-1 react-hook-form ์ด์ฉํ๊ธฐ
๋จผ์ npm install react-hook-form์ ํ์ฌ ์ค์นํ ํ์ ๊ณต์ ํํ์ด์ง(https://react-hook-form.com/kr/get-started/)์ ์๋ด๋ ๋๋ก ์คํํด ๋ณด์์ผ๋ "Uncaught TypeError: path.split is not a function" ๋ ์๋ฌ๊ฐ ๋ด๋ค.๊ฒ์ํด๋ณด๋ ์ฌ๋ฌ ํด๊ฒฐ๋ฐฉ๋ฒ ์ค react-hook-form ๋ฒ์ ์ 6์ผ๋ก ๋ฎ์ถ๋ฉด ๋๋ค๊ณ ํด์ ๋ค์ npm install react-hook-form@6์ผ๋ก ์ฌ์ค์น ํ ์งํํ์๋ค.
๊ณต์ ํํ์ด์ง์ ํ๊ตญ์ด ๋ฒ์ ๋ ์์ด์ handleSubmit, register, watch, errors ๋ฑ ์ฌ๋ฌ๊ธฐ๋ฅ์ ์ฝ๊ฒ ์ ์ด์ฉํ ์ ์์๋ค. ์๋ฅผ ๋ค์ด, handleSubmit์ผ๋ก ํผ์ onSubmit ์ด๋ฒคํธ๋ฅผ ์คํํ๋ฉด e.preventDefault( )๋ฅผ ๊ตณ์ด ์ ์ง ์์๋ ์ด์ ๊ฐ์ด ๋์๋๊ณ , register์ validate ์์ฑ์ ํตํด '๋น๋ฐ๋ฒํธ'์ '๋น๋ฐ๋ฒํธ ํ์ธ'์ ๋ฌธ์๊ฐ ๋์ผํ์ง๋ ์ฝ๊ฒ ํ์ธํ ์ ์๋ค.
๋์ค์ ๋ง์ ์ฝ๊ด๋์ ์ฒดํฌ๋ฐ์ค๋ react-hook-form์ ์ด์ฉํด ์์ ํด๋ด์ผ๊ฒ ๋ค. ์ผ๋จ ์ค๋์ ์ฌ๊ธฐ๊น์ง ํ์๊ฐ์ ์ ํจ์ฑ ๊ฒ์ฌ๊ธฐ๋ฅ์ ์์ ๋.
'[PROJECT] ๋ด์ผ์ ์ง' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
#6. ๋ก๊ทธ์ธ ๊ธฐ๋ฅ ๊ตฌํ (1์ฐจ) (1) | 2021.10.04 |
---|---|
#5. ์ฝ๊ด๋์ ์ฒดํฌ๋ฐ์ค ๊ธฐ๋ฅ ๊ตฌํ (2) | 2021.09.27 |
#4. ์บ๋ก์ (Carousel) ๊ตฌํํ๊ธฐ (0) | 2021.09.25 |
#3. ๋ชจ๋ฌ์ฐฝ ๊ตฌํ( feat. ์์ญ ๋ฐ ํด๋ฆญ ์ ๋ซ๊ธฐ) (0) | 2021.09.15 |
#2. ๋ก๊ทธ์ธ ๊ธฐ๋ฅ ๊ฐ๋ ์ก๊ธฐ (0) | 2021.09.13 |