-
Notifications
You must be signed in to change notification settings - Fork 40
[우재현] Sprint8 #269
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
[우재현] Sprint8 #269
The head ref may contain hidden characters: "React-\uC6B0\uC7AC\uD604-sprint8"
Conversation
변경사항 - Item컴포넌트에서 ListItem으로 파일명 변경 - TS로 마이그레이션
|
수고 하셨습니다 ! 스프리트 미션 하시느라 정말 수고 많으셨어요. |
| <<<<<<< HEAD | ||
| ======= | ||
| # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
|
||
| >>>>>>> cde515c40685c7ea849fcafc91354005f21c13fd |
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.
컨플릭트 해결 중 누락된 건이 있는 것 같아요 !
| <<<<<<< HEAD | ||
| # End of https://www.toptal.com/developers/gitignore/api/react,nextjs,sass | ||
| ======= | ||
| # End of https://www.toptal.com/developers/gitignore/api/react,nextjs,sass | ||
| .env.local | ||
| .env.development.local | ||
| .env.test.local | ||
| .env.production.local | ||
|
|
||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| >>>>>>> cde515c40685c7ea849fcafc91354005f21c13fd |
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.
컨플릭트 해결 중 누락된 건이 있는 것 같아요 !
| page: number = 1, | ||
| pageSize: number = 12, | ||
| orderBy: string = "recent", | ||
| keyword: string | undefined = undefined |
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.
다음과 같이 옵셔널 프로퍼티로 작성할 수 있습니다 ! 😊
| keyword: string | undefined = undefined | |
| keyword?: string = undefined |
| export async function getProductList( | ||
| page: number = 1, | ||
| pageSize: number = 12, | ||
| orderBy: string = "recent", |
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.
타입 범위를 좁힐 수 있을 것 같아요 ! 😊
| orderBy: string = "recent", | |
| orderBy: "recent" | "liked" = "recent", |
|
|
||
| const BASE_URL = process.env.REACT_APP_API_BASE_URL; | ||
|
|
||
| export async function getProductList( |
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 handleFeatureClick = (e) => { | ||
| if (e.target.classList.contains("feature")) { | ||
| setSelectedComment(e.currentTarget.dataset.id); | ||
| const [comments, setComments] = useState<CommentList | undefined>(); |
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.
기본값이 빈 값으로 되어 있다면 자동으로 undefined이 추론됩니다 !
| const [comments, setComments] = useState<CommentList | undefined>(); | |
| const [comments, setComments] = useState<CommentList>(); |
| const [selectedComment, setSelectedComment] = useState<string | null>(null); | ||
| const [isEditing, setIsEditing] = useState<string | null>(null); | ||
| const selectRef = useRef<HTMLUListElement | null>(null); |
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.
굳굳 ! null을 고려한 타입을 잘 설정하셨군요 ㅎㅎㅎ 👍
| const [selectedComment, setSelectedComment] = useState<string | null>(null); | |
| const [isEditing, setIsEditing] = useState<string | null>(null); | |
| const selectRef = useRef<HTMLUListElement | null>(null); | |
| const [selectedComment, setSelectedComment] = useState<string>(null); | |
| const [isEditing, setIsEditing] = useState<string>(null); | |
| const selectRef = useRef<HTMLUListElement | null>(null); |
| alert( | ||
| `test : comment id ${event.currentTarget.dataset.id} 삭제 되었습니다` | ||
| ); |
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.
사용자 알림도 너무 좋아요 ㅎㅎㅎ
| isSelected: any; | ||
| onClick: any; | ||
| onSelect: 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.
다음 미션 때에는 다음과 유사하게 정의되도록 해봅시다 !
| isSelected: any; | |
| onClick: any; | |
| onSelect: any; | |
| isSelected: boolean; | |
| onClick: (selectedId) => void; | |
| onSelect: (selectedId) => void; |
위에 작성된 코드는 검증되지 않은 타입입니다 ! 한번 확인해봐주세요 ㅎㅎㅎ 관건은
any를 쓰지 말자 ! 로 보시면 될 것같아요.
아마도, 어떤 원인이 있어서 일단은 any로 두신 것 같아요 ! 차근차근 지워봅시다 !
| import useDebounce from "../hooks/useDebounce"; | ||
|
|
||
| const DeviceTypeContext = createContext(); | ||
| export type DeviceType = "desktop" | "tablet" | "mobile"; |
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.
유니온 타입을 적절하게 설정하셨군요 ! 훌륭합니다 ㅎㅎㅎ
|
수고 많으셨습니다 재현님 ! 그 간 정말 고생 많으셨고 앞으로도 승승장구하시길 진심으로 기원합니다 ! 🙇♂️🙇♂️ |
|
조건 분기를 통해 여러 경우를 한 번에 처리하는 함수가 많습니다.
나름 잘 만든 함수라고 생각했었는데 TS로 마이그레이션 해보니 엉망인 거 같습니다. 가장 문제가 되는 건 변수의 타입이 불명확하다 보니 필요할 때 마다 타입을 명시 해줘야 하고, 이로 인해 코드 또한 효율성과 가시성이 많이 떨어 져 보입니다. 그래서 이러한 부분을 개선해 아래처럼 바꿔보려고 하는데 멘토님의 고견을 듣고 싶습니다!
const handleChangeObject = (e) => { ... }
const handleChangeArray = (e) => { ... }
const handleChangeString = (e) => { ... }
const handleChange = (e) => {
if(객체일 때) handleChangeObject(e);
if(배열일 때) handleChangeArray(e);
if(문자열일 때) handleChangeString(e);
...
} |
|
음 함수의 책임이 많아짐에따라 단일 책임원칙이 위배될 수 있고, 여러 유니온 타입 혹은 오버로딩에 의해 타입 안전성이 저하될 수 있다고 판단되기에 각각의 상태 별로 핸들러를 작성했을 것 같아요. |
요구사항
기본
심화
멘토에게