-
Notifications
You must be signed in to change notification settings - Fork 117
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
[김민정] Week20 #1086
The head ref may contain hidden characters: "part3-\uAE40\uBBFC\uC815-week20"
[김민정] Week20 #1086
Conversation
- 파일 경로 수정 - Image, a 태그를 Image, Link태그로 수정
전에 쓰던 코드 내용이 복잡하고, input으로 props도 많이 넘겨주는 것 같아 코드를 수정했습니다.
- modal portal을 이용해 토스트 컴포넌트 화면에 띄우도록 하였고, context API를 이용해 전역적으로 관리가 가능하도록 구현하였습니다.
- 토스트 반응형으로 수정 - 인풋에 키보드 이벤트 추가
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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.
늦게 드려서 죄송해요ㅠㅠ
수고하셨습니다 :)
eventFunc: { | ||
onFocusOut: () => void; | ||
onChange: () => void; | ||
onKeydown: (e: React.KeyboardEvent<HTMLInputElement>) => void; | ||
} |
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.
JSX.IntrinsicElements['input']
쓰셔도 괜찮을 거 같아요!
} | ||
}; | ||
|
||
},[inputErrorInfo]) | ||
|
||
return ( | ||
<InputDiv> | ||
<p>{title}</p> | ||
<EmailPasswordInput | ||
type={isViewPassword ? "text" : type} |
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.
type 도 string 보다 조금 더 구체적인 타입을 가지거나 기존 Input 의 type 프로퍼티를 확장하면 좋을 거 같아요!
const openDeleteModal = () => { | ||
modal.openModal(<DeleteModal />); | ||
}; |
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(!modalRoot) return; | ||
|
||
return createPortal(children, modalRoot) |
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.
👍
type ToastType = { | ||
errorMessage?:string | null; | ||
isToastView: boolean, | ||
setIsToastView: React.Dispatch<React.SetStateAction<boolean>>; |
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.
아마 useState 의 setter 부분일 거 같은데, setter 를 바로 setter 에서 넘기는 것보다는 해당 useState 를 선언한 곳에서 해당 setter 를 감싼 callback 을 만들고 그 callback 을 넘겨주시는 걸 추천드려요!
한 컴포넌트에서 선언한 state 는 해당 컴포넌트 안에서만 변경할 수 있게 하는 게 좋아요:)
@@ -0,0 +1,8 @@ | |||
|
|||
const ToastPortalContent = ({children}: {children?:any}) => { |
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.
children 만 리턴해주는 기능이라면 <></> 랑 다를 게 없어서 따로 컴포넌트로 만들지 않아도 될 거 같아요~!
export const useModal = () => { | ||
const context = useContext(ModalContext); | ||
if(!context) throw new Error ("modal error"); | ||
return context; | ||
}; |
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 openModal = (modal: React.ReactNode) => { | ||
setIsOpen(true); | ||
setModalComponent(modal); |
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.
현재 구조를 보면 children 으로 온 모달말고도, 모달 내부에 있을 내부모달(?)로 추정되는 modalCompenent 도 렌더부에서 병렬적으로 배치하셨는데, 만약 모달 내 모달이 맞다면 해당 children 으로 들어오는 곳에서 modal 을 다시 정의하는 게 자연스러울 거 같아요!
@@ -3,29 +3,30 @@ import { postCheckDuplicationEmail } from "@/api/api"; | |||
|
|||
// 이메일 유효성 검사 | |||
function emailCheck(email_address: string) { | |||
let email_regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i; | |||
const email_regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i; | |||
return Boolean(email_regex.test(email_address)); |
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.
test 가 return 값이 boolean 이라 따로 래핑 안해주셔도 될 거 같아요!
export const emailInputValidationcheck = (email: string): ErrorValid => { | ||
let emailValid: ErrorValid; | ||
if (!email) { | ||
status = INPUT_STATUS.noEmail; | ||
emailValid = INPUT_STATUS.noEmail; | ||
} else if (!emailCheck(email)) { | ||
status = INPUT_STATUS.wrongEmail; | ||
emailValid = INPUT_STATUS.wrongEmail; | ||
} else { | ||
status = "valid"; | ||
emailValid = "valid"; | ||
} | ||
return status; | ||
return emailValid; |
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.
early return 적용하면 emailValid 변수 선언 필요없을 거 같아요!
주요 변경사항
스크린샷
vercel: https://4-weekly-mission-git-part3-week20-kim-minjeongs-projects.vercel.app/
토스트 컴포넌트
멘토에게
그냥 제출했습니다... 이 점 고려하시고 봐주세요!