-
Notifications
You must be signed in to change notification settings - Fork 45
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
[조혜진] Week14 #430
The head ref may contain hidden characters: "part3-\uC870\uD61C\uC9C4-week14"
[조혜진] Week14 #430
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요구사항 거의 다 작업하셨군요 수고 많으셨어요!! 💯
전체적으로 깔끔하게 잘 작성해주셨고, 약간의 중복 코드 개선을 고민해보시면 좋을 것 같아요!
<Header /> | ||
<Main /> | ||
<Footer /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
페이지마다 Header, Footer 가 반복된다면 Layout 컴포넌트를 만들어 분리하는 것도 방법입니다!
if (!value) { | ||
setErrorMessage(placeholder); | ||
} else if (id === "email" && !validateEmail(value)) { | ||
setErrorMessage("올바른 이메일 주소가 아닙니다."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
보통 요런 에러메세지도 상수로 분리해서 관리하곤 합니다!
코드에 텍스트가 섞여있으면 나중에 수정해야할 때 코드 내에서 찾는 게 번거롭기도 하고,
동일한 텍스트가 여러 케이스에서 사용되는 경우도 있어서요
className={`${styles.input} ${ | ||
errorMessage || externalErrorMessage ? styles.invalid : "" | ||
}`} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제가 멘토링 때 알려드린 classnames 라이브러리를 요럴 때 쓰시면 편합니다!
className={`${styles.eye_button} ${passwordVisible ? styles.on : ""}`} | ||
onClick={handleEyeToggle} | ||
type='button' | ||
></button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
내부에 자식 없으면 self closing 으로 많이 써요
></button> | |
/> |
import { useRouter } from "next/router"; | ||
|
||
function SignIn() { | ||
const [email, setEmail] = useState<string>(""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
타입스크립트는 할당된 값을 참조하여 타입 추론을 하기 때문에 이 경우에는 명시적으로 타입 지정하지 않아도 됩니다!
const [email, setEmail] = useState<string>(""); | |
const [email, setEmail] = useState(""); |
(초기값 ''
을 보고 알아서 타입을 string 으로 유추함)
useEffect(() => { | ||
const accessToken = localStorage.getItem("accessToken"); | ||
if (accessToken) { | ||
router.push("/folder"); | ||
} | ||
}, [router]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이것도 여러번 반복되니 커스텀훅으로 분리해도 좋겠네요 !
if (emailStatus) { | ||
setEmailError(emailStatus); | ||
} else { | ||
setEmailError(""); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요렇게도 바꿀 수 있겠군요
if (emailStatus) { | |
setEmailError(emailStatus); | |
} else { | |
setEmailError(""); | |
} | |
setEmailError(emailStatus || ''); |
useEffect(() => { | ||
const fetchData = async () => { | ||
try { | ||
const response = await fetch(`${BASE_URL}check-email`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify(body), | ||
}); | ||
const data = await response.json(); | ||
setData(data); | ||
if (response.status === 409) { | ||
setStatus("이미 사용 중인 이메일입니다."); | ||
} else { | ||
setStatus(""); | ||
} | ||
} catch (error) { | ||
console.error("Error post data:", error); | ||
} | ||
}; | ||
|
||
if (body.email) { | ||
fetchData(); | ||
} | ||
}, [body.email]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useEffect 쓰지 않고 input 에 change 이벤트 실행 시마다 확인하는 방법도 있을 것 같아요!
현재 방식 유지하더라도 오늘 배운 debounce 활용해보면 좋을 것 같고요!
요구사항
기본
심화
주요 변경사항
스크린샷
멘토에게