diff --git a/keyword/chapter05/keyword.md b/keyword/chapter05/keyword.md new file mode 100644 index 0000000..113fd13 --- /dev/null +++ b/keyword/chapter05/keyword.md @@ -0,0 +1,45 @@ +- useRef ๐Ÿ  + + ํ•จ์ˆ˜ํ˜• ์ปดํฌ๋„ŒํŠธ ๋‚ด์—์„œ DOM ์š”์†Œ๋‚˜ ๋‹ค๋ฅธ React ์š”์†Œ๋ฅผ ์ฐธ์กฐํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋˜๋Š” Hook + + - ๊ธฐ๋ณธ ํ˜•ํƒœ + + ```jsx + const ๋ณ€์ˆ˜๋ช… = useRef(์ดˆ๊ธฐ๊ฐ’); + ``` + + ๊ฒฐ๊ณผ๊ฐ’์œผ๋กœ ์ดˆ๊ธฐ๊ฐ’ {current : ์ดˆ๊ธฐ๊ฐ’}์„ ์ง€๋‹Œ ๊ฐ์ฒด๊ฐ€ ๋ฐ˜ํ™˜ + + - ํŠน์ง• + 1. ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๊ณ„์†ํ•ด์„œย **๋ Œ๋”๋ง์ด ๋˜์–ด๋„**ย ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์–ธ๋งˆ์šด๋“œ๋˜๊ธฐ ์ „๊นŒ์ง€๋Š”ย **๊ฐ’์„ ๊ทธ๋Œ€๋กœ ์œ ์ง€** + 2. **currnet ์†์„ฑ์€ ๊ฐ’์„ ๋ณ€๊ฒฝํ•ด๋„**ย ์ƒํƒœ๋ฅผ ๋ณ€๊ฒฝํ•  ๋•Œ ์ฒ˜๋Ÿผย **React ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์žฌ๋ Œ๋”๋ง ๋˜์ง€ ์•Š์Œ โ†’ ์„ฑ๋Šฅํ–ฅ์ƒ** + - useRef๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ + 1. ์ปดํฌ๋„ŒํŠธ์˜ ๋ Œ๋”๋ง๊ณผ ๊ด€๋ จ์ด ์—†๋Š” ๊ฐ’๋“ค์„ ์ €์žฅํ•  ๋•Œ + 2. DOM ์š”์†Œ์— ๋Œ€ํ•œ ์ฐธ์กฐ๋ฅผ ์ €์žฅํ•  ๋•Œ + 3. ๋ Œ๋”๋ง ๊ณผ์ •์—์„œ ๊ฐ’์ด ๋ณ€๊ฒฝ๋˜์–ด๋„ ๋‹ค์‹œ ๋ Œ๋”๋ง๋˜์ง€ ์•Š์•„๋„ ๋˜๋Š” ๊ฒฝ์šฐ + +- input์˜ ์ฃผ์š” ํ”„๋กœํผํ‹ฐ ๐Ÿ  + - ์•„๋ž˜ ๋‚ด์šฉ ์ด์™ธ์—, ์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” ํ”„๋กœํผํ‹ฐ๊ฐ€ ์žˆ์œผ๋ฉด ์ถ”๊ฐ€๋กœ ๋” ์ •๋ฆฌํ•ด์ฃผ์„ธ์š”! ๐Ÿ  + - **pattern**: ํŠน์ • ์ •๊ทœํ‘œํ˜„์‹์„ ์ ์šฉํ•˜์—ฌ ์ž…๋ ฅ ๊ฐ’์„ ๊ฒ€์‚ฌํ•จ + + ```html + + + + ``` + + - **autofocus**: ํŽ˜์ด์ง€ ๋กœ๋“œ ์‹œ ํ•ด๋‹น ์ž…๋ ฅ ํ•„๋“œ์— ์ž๋™์œผ๋กœ ํฌ์ปค์Šค๋ฅผ ์„ค์ • + + ```html + + + + ``` + + - **size**: ์ž…๋ ฅ ํ•„๋“œ์˜ ๋„ˆ๋น„(๊ธ€์ž ์ˆ˜ ๊ธฐ์ค€)๋ฅผ ์ง€์ • + + ```html + + + + ``` \ No newline at end of file diff --git a/keyword/chapter05/loginPage.jsx b/keyword/chapter05/loginPage.jsx new file mode 100644 index 0000000..4798e1d --- /dev/null +++ b/keyword/chapter05/loginPage.jsx @@ -0,0 +1,33 @@ +import useForm from "../../../hooks/useForm.js"; +import './loginPage.css'; +import {validateLogin} from "../../../utils/validate"; + +const LoginPage = ()=>{ + const login = useForm({ + initialValue:{ + email: '', + password: '', + }, + validate: validateLogin + }) + return( +
+

๋กœ๊ทธ์ธ

+
+ + {login.touched.email && login.errors.email &&

{login.errors.email}

} + + {login.touched.password && login.errors.password &&

{login.errors.password}

} + {(login.touched.password && !login.errors.password &&login.touched.email && !login.errors.email) + ? + :} + +
+
+ + ) +} + +export default LoginPage; \ No newline at end of file diff --git a/keyword/chapter05/myloginPage.css b/keyword/chapter05/myloginPage.css new file mode 100644 index 0000000..c69787d --- /dev/null +++ b/keyword/chapter05/myloginPage.css @@ -0,0 +1,22 @@ +.login_form_container{ + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + width: 100%; +} +.login_form input{ + height: 50px; + width: 350px; + border-radius: 8px; +} +.login_form p{ + margin-top: 0px ; + font-size: 13px; +} +.submit { + background-color: #ff007c; + color: white; + font-weight: 400; + font-size: 16px +} \ No newline at end of file diff --git a/keyword/chapter05/myloginPage.jsx b/keyword/chapter05/myloginPage.jsx new file mode 100644 index 0000000..67a2975 --- /dev/null +++ b/keyword/chapter05/myloginPage.jsx @@ -0,0 +1,40 @@ +import { useForm } from "react-hook-form"; +import { useState } from "react"; +import * as yup from 'yup'; +import {yupResolver} from '@hookform/resolvers/yup'; +import './loginPage.css'; +const LoginPage = ()=>{ + const emailSchema = yup.object().shape({ + email : yup.string().email('์˜ฌ๋ฐ”๋ฅธ ์ด๋ฉ”์ผ ํ˜•์‹์ด ์•„๋‹™๋‹ˆ๋‹ค ๋‹ค์‹œ ํ™•์ธํ•ด์ฃผ์„ธ์š”!').required('์ด๋ฉ”์ผ์„ ๋ฐ˜๋“œ์‹œ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.'), + }) + const pwdSchema = yup.object().shape({ + password : yup.string().min(8,'๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” 8์ž~ 16์ž ์‚ฌ์ด๋กœ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”!',).max(16,'๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” 8์ž~ 16์ž ์‚ฌ์ด๋กœ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”!').required('๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ๋ฐ˜๋“œ์‹œ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.'), + }) + const emailForm = useForm({ + resolver: yupResolver(emailSchema) + }) + const pwdForm = useForm({ + resolver: yupResolver(pwdSchema) + }) + + const onSubmit = (data)=>{ + console.log('ํผ ๋ฐ์ดํ„ฐ ์ œ์ถœ'); + console.log(data); + } + + return( +
+

๋กœ๊ทธ์ธ

+
+ +

{emailForm.formState.errors.email?.message}

+ +

{pwdForm.formState.errors.password?.message}

+ +
+
+ + ) +} + +export default LoginPage; \ No newline at end of file