-
Notifications
You must be signed in to change notification settings - Fork 1
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
[3주차-ts] 이상형 with TS #6
base: main
Are you sure you want to change the base?
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.
혠니 응원한다구💛💛💛💛
모르는거 이씀 질문 갈겨~
week3_ts/src/pages/Main.tsx
Outdated
navigation("/complete", { | ||
// navigation에 값을 다중으로 넘겨주는 방법 | ||
state: { checkLists: checkLists("16강"), matchWinners: matchWinners }, | ||
}); | ||
} |
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.
내가 혠니랑 열띤 토론하고나서 이제 다시 찾아보니까 Common API reference - 리액트 navigate에서 보면 navigation.navigate(name, params)
형태로 들어가는 거라서 저기 params에는 함수나 컴포넌트가 들어갈수 없는 것같아!
그래서 값을 다중으로 넘기려면
state: { checkLists: "16강", matchWinners: "이겻다" },
이런식으로 얼마든지 가능한데! 혠니 코드는 함수랑 ref 자체를 넘겨받는거라 인식을 못하는 것같아! 여기서 state를 넘겨주지 말고 몬가 props로 넘기거나 그래야 할 것가튼데 흠흠 혹싀 이해 안데면 알랴주구 >.<
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.
오 .... !! 값을 다중으로 넘기는 건 가능하되, 함수랑 ref 자체를 넘기는 건 안된다! 그러므로 props를 사용해야된단 뜻이겠지?!
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.
고생했어요 !!!!~
초기세팅 직접 한 건가요?? awesome 하네요🔥🔥🔥🎈
MainHeader
, Tournament
는 Main 페이지서,
WinnerSection
은 Complete 페이지서 불러오는 컴포넌트니까,
components/main/MainHeader
components/main/Tournament
components/complete/WinnerSection
로 하면 더 명확한 폴더구조가 될 것 같네요!!!
TS 도 깔끔하게 뚝딱뚝딱 해내신 거 멋집니다 !!! 화이팅👍👍
week3_ts/src/assets/images/index.ts
Outdated
export interface HandsomeGuy { | ||
name: string; | ||
url: string; | ||
} | ||
|
||
export const handsomeGuys: HandsomeGuy[] = [ | ||
{ | ||
name: "김종인", | ||
url: jongIn, | ||
}, |
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.
assets/images 폴더에는 이미지 파일만 위치시키고,
해당하는 handsomeGuys
객체배열은 다른 폴더에 정의해서 export 시키는 것이 더 의미분리가 될 것이라 생각해요!!~
(assets 폴더가 아닌, constant나 core 폴더같은)
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.
흐핳ㅎㅎ내가 이러케 했오 ㅎㅎㅎ혠니 내 코드 참고하누라,,,ㅎㅎㅎ나도 배워가겠샴~
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.
넵넵!! export 하는 다른 파일을 만들어보겠슴다!
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.
는 그냥 파일만 이동시킴 되군요 헤헷
week3_ts/src/pages/Main.tsx
Outdated
useEffect(() => { | ||
if (fighterList.length === 0 && matchWinners.current.length >= 8) checkLists("8강"); | ||
else if (fighterList.length === 0 && matchWinners.current.length >= 4) checkLists("4강"); | ||
else if (fighterList.length === 0 && matchWinners.current.length >= 2) checkLists("결승"); | ||
else if (fighterList.length === 0 && matchWinners.current.length === 1) { | ||
console.log(matchWinners.current[0]); | ||
navigation("/complete", { | ||
// navigation에 값을 다중으로 넘겨주는 방법 | ||
state: { matchWinners }, | ||
}); | ||
} | ||
}); |
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
를 사용할 떄는 엔간해서 두번째 인자를 설정해주는 것이 좋다고 알고 있는데,
따로 이유가 있을까요??
공식문서
useEffect 내에서는 figtherList와 matchWinner만 활용하는 데에 비해,
두번째 인자를 설정하지 않는다면 해당 변수 외에 모든 것이 변할 때 (리렌더링 될 떄) 마다 콜백을 실행시키게 됩니다
무한 루프에 갇히게 될 가능성도 있고, 불필요한 렌더링이 지속적으로 일어나게 될 것 같아요!
useEffect(() => { | |
if (fighterList.length === 0 && matchWinners.current.length >= 8) checkLists("8강"); | |
else if (fighterList.length === 0 && matchWinners.current.length >= 4) checkLists("4강"); | |
else if (fighterList.length === 0 && matchWinners.current.length >= 2) checkLists("결승"); | |
else if (fighterList.length === 0 && matchWinners.current.length === 1) { | |
console.log(matchWinners.current[0]); | |
navigation("/complete", { | |
// navigation에 값을 다중으로 넘겨주는 방법 | |
state: { matchWinners }, | |
}); | |
} | |
}); | |
useEffect(() => { | |
if (fighterList.length === 0 && matchWinners.current.length >= 8) checkLists("8강"); | |
else if (fighterList.length === 0 && matchWinners.current.length >= 4) checkLists("4강"); | |
else if (fighterList.length === 0 && matchWinners.current.length >= 2) checkLists("결승"); | |
else if (fighterList.length === 0 && matchWinners.current.length === 1) { | |
console.log(matchWinners.current[0]); | |
navigation("/complete", { | |
// navigation에 값을 다중으로 넘겨주는 방법 | |
state: { matchWinners }, | |
}); | |
} | |
}, [fighterList, matchWinner.current]); |
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를 사용할 때 두번째 인자를 붙이는 걸 자꾸 잊어버리는 거 같아요 제대로 사용하겠심다 !.!
week3_ts/src/pages/Main.tsx
Outdated
else if (fighterList.length === 0 && matchWinners.current.length >= 4) checkLists("4강"); | ||
else if (fighterList.length === 0 && matchWinners.current.length >= 2) checkLists("결승"); | ||
else if (fighterList.length === 0 && matchWinners.current.length === 1) { | ||
console.log(matchWinners.current[0]); |
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 countRoundNum = (): number => { | ||
return matchWinners.current.length + 1; | ||
}; | ||
// 이번 강에는 총 몇 번의 라운드가 있는지 | ||
const totalRoundNum = (): number => { | ||
return Math.ceil((fighterList.length + matchWinners.current.length * 2) / 2); | ||
}; |
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 countRoundNum = (): number => { | |
return matchWinners.current.length + 1; | |
}; | |
// 이번 강에는 총 몇 번의 라운드가 있는지 | |
const totalRoundNum = (): number => { | |
return Math.ceil((fighterList.length + matchWinners.current.length * 2) / 2); | |
}; | |
// 현재 몇 라운드인지 | |
const countRoundNum = matchWinners.current.length + 1; | |
// 이번 강에는 총 몇 번의 라운드가 있는지 | |
const totalRoundNum = Math.ceil((fighterList.length + matchWinners.current.length * 2) / 2); |
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.
그러게!! 나도 궁금하다!!!!!!!!!!
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 StyledRoot = styled.div` | ||
display: flex; | ||
flex-direction: column; |
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.
Main 페이지에서도 그렇고, StyledRoot
는 어떤 의미인지 궁금합니다!!!
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 최상단 div 레이아웃?!
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.
그리고 궁금한거! 여기서만 Styled라고 명시한 이유는?? 다른데서는 그냥 GameTitle 이렇게 쓰는데!
차이가 머에여?!
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.
원래 최상단루트는 StyledRoot로 두는데, 컴포넌트 분리를 하면서 마음대로 쓰게 된거 같아요잇. 페이지 최상단 루트를 제외하고 수정하겠습니다~!
font-family: "HaenamFont"; | ||
`; | ||
|
||
const GameTitle = styled.header` |
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.
왕 시멘틱 태그 좋네요🤩🤩 h1
나 h2
같은 헤딩태그는 어떨까요??
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.
오오 넵넵 !!!!!!! 좋으네요
<StyledRoot> | ||
<p>👑</p> | ||
<article> | ||
<img src={matchWinners.current[0].url} /> |
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.
img
태그에는 alt
속성이 필수로 들어가는 것이 웹표준에 적합합니다!
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.
추가로 alt 속성은
- 만약 이미지가 정보를 포함하고 있다면, 텍스트는 이미지를 묘사해야 한다.
- 만약 이미지가 요소 내에 위치하고 있다면, 텍스트는 링크가 어디와 연결되어 있는지를 설명해야 한다.
- 만약 이미지가 단순한 장식이라면 alt=""와 같이 사용해야 한다.
라는 규칙이 있슴댜~.~
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.
오 넵!!!!!!!!!!!!감사합니다!!!!!!!!
<p>👑</p> | ||
<article> | ||
<img src={matchWinners.current[0].url} /> | ||
<div>{matchWinners.current[0].name}</div> |
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.
strong
같은 태그도 적합할 것 같다는 생각이 듭니다 !!~
p { | ||
position: absolute; | ||
z-index: 999; | ||
font-size: 8rem; | ||
} | ||
article { | ||
width: 35rem; | ||
cursor: pointer; | ||
position: relative; | ||
display: flex; | ||
justify-content: center; | ||
|
||
img { | ||
width: 100%; | ||
} | ||
div { | ||
position: absolute; | ||
top: 75%; | ||
left: 50%; | ||
font-size: 5rem; | ||
color: white; | ||
transform: translate(-50%, -50%); | ||
text-shadow: -0.2rem 0 black, 0 0.2rem black, 0.2rem 0 black, 0 -0.2rem black; | ||
} | ||
} |
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.
이정도 뎁스의 스타일링은 따로 선언하여 작성하는 것이 후의 유지보수에도, 가독성 측면에서도 더 좋다고 생각해요!
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.
>
요렇게 명시해주는게 더 좋을것같아여!
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.
선택자 없이 사용하는건 지양해야델듯?!!
{fighterList.map((fighter, index) => { | ||
if (index < 2) { | ||
return ( | ||
<article onClick={() => getSelectWinner(index)} key={index}> | ||
<img src={fighter.url} /> | ||
<div>{fighter.name}</div> | ||
</article> | ||
); | ||
} | ||
})} |
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.
{fighterList.map((fighter, index) => { | |
if (index < 2) { | |
return ( | |
<article onClick={() => getSelectWinner(index)} key={index}> | |
<img src={fighter.url} /> | |
<div>{fighter.name}</div> | |
</article> | |
); | |
} | |
})} | |
{fighterList.slice(0, 2).map((fighter, index) => ( | |
<article onClick={() => getSelectWinner(index)} key={index}> | |
<img src={fighter.url} /> | |
<div>{fighter.name}</div> | |
</article> | |
)} |
이렇게도 축약할 수 있을 것 같네요!?
week3_ts/vite.config.ts
Outdated
import { defineConfig } from 'vite' | ||
import react from '@vitejs/plugin-react' | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [react()] |
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 [round, setRound] = useState("16강"); | ||
const matchWinners = useRef([]); | ||
const [fighterList, setFighterList] = useState(randomGameInfo); | ||
const [gameEnd, setGameEnd] = useState(false); |
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 [round, setRound] = useState("16강"); | |
const matchWinners = useRef([]); | |
const [fighterList, setFighterList] = useState(randomGameInfo); | |
const [gameEnd, setGameEnd] = useState(false); | |
const [round, setRound] = useState<string>("16강"); | |
const matchWinners = useRef<array>([]); | |
const [fighterList, setFighterList] = useState<여기도 타입 지정>(randomGameInfo); | |
const [gameEnd, setGameEnd] = useState<boolean>(false); |
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.
state, ref에도 타입지정 필요합니다!!
react-hook : 서히 벨로그
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.
@Happhee 초기값 설정하면 자동으로 타입추론이 되긴 해요 !!~@
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.
@joohaem 그건 아는데 !! 그래도 명시 해주는게 맞는방법아니야?!! 추론하게 하는게 타입스크립트를 쓰는 이유가 맞는걸까? 라는 의문이 들었오!
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 getSelectWinner = (pos) => { | ||
matchWinners.current.push(fighterList[pos]); | ||
setFighterList(fighterList.slice(2)); | ||
}; |
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.
요기도 매개변수 타입 지정!!!!!!!!🚨🚨🚨🚨🚨🚨
타입스크립트에서 변수에는 타입 무조건 갈기자🚨🚨🚨
} | ||
|
||
export default function MainHeader(props: MainHeaderProps) { | ||
const { round, matchWinners, fighterList } = props; |
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 StyledRoot = styled.div` | ||
display: flex; | ||
flex-direction: column; |
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.
그리고 궁금한거! 여기서만 Styled라고 명시한 이유는?? 다른데서는 그냥 GameTitle 이렇게 쓰는데!
차이가 머에여?!
const { matchWinners, fighterList, setFighterList } = props; | ||
|
||
// 승자를 골랐을 때 | ||
const getSelectWinner = (pos: number) => { |
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.
아여기썻넹 ㅎㅎ
오늘도 할할놀놀을 몸소 실천 중인 웹파트원 ! 화이팅 :) |
✨ 구현 기능 명세
🎁 PR Point
😭 어려웠던 점
😎 구현 결과물