-
Notifications
You must be signed in to change notification settings - Fork 44
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
[박상준] Week12 #395
The head ref may contain hidden characters: "part2-\uBC15\uC0C1\uC900-week12"
[박상준] Week12 #395
Conversation
수고 하셨습니다 ! 위클리 미션 하시느라 정말 수고 많으셨어요. |
|
||
function App() { | ||
const userId = 1; | ||
const userId: number = 1; |
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 userId: number = 1; | |
const userId = 1; // `userId`는 `Number`입니다 😊 |
import { ReactNode } from 'react'; | ||
import ReactDom from 'react-dom'; | ||
|
||
const ModalPortal = ({ children }: { children: ReactNode }) => { |
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.
굳굳 ! 포탈을 통해서 모달을 만드셨군요 😊👍
@@ -0,0 +1,82 @@ | |||
import axios from '../instance/axiosInstance'; |
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.
(제안)axios
라고 작성되면 axios
라이브러리를 직접 사용하는 것과 혼동이 올 수 있을 것 같아요 !
axios
인스턴스임을 명시하는게 더욱 좋을 것 같습니다 😊
import axios from '../instance/axiosInstance'; | |
import instance from '../instance/axiosInstance'; |
|
||
export async function getSampleUser() { | ||
try { | ||
const { data } = await axios.get('/sample/user'); |
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.
AxiosResponse
타입을 지정해볼까요?:
const { data } = await axios.get('/sample/user'); | |
const { data } = await axios.get<{ | |
id: string; | |
email: string; | |
// ... | |
}>('/sample/user'); |
|
||
export async function getSampleUser() { | ||
try { | ||
const { data } = await axios.get('/sample/user'); |
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.
외부에서 해당 API의 타입이 필요할 경우 다음과 같이 작성할 수 있습니다:
export async function getSampleUser() { | |
try { | |
const { data } = await axios.get('/sample/user'); | |
type GetSampleUserResponse = AxiosResponse<{ | |
id: string; | |
email: string; | |
//... | |
}> | |
export async function getSampleUser() { | |
try { | |
const { data } = await axios.get('/sample/user'); |
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 async function getSampleUser() { | |
try { | |
const { data } = await axios.get('/sample/user'); | |
// 외부 파일 | |
export type SampleUser = { | |
id: string; | |
email: string; | |
// .... | |
} | |
// src/api/api.ts | |
type GetSampleUserResponse = AxiosResponse<Pick<SampleUser, 'id' | 'email' /* ... */>> | |
export async function getSampleUser() { | |
try { | |
const { data } = await axios.get('/sample/user'); |
} | ||
} | ||
|
||
export async function getFolderList(id: number, folderId: 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.
파라메터가 어떤 것들이 있는지 타입과 네이밍이 명확해서 보기 좋네요 😊👍
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.
또한, folderId
는 string
으로 활용되지 않나요?
추 후 수식과 관련된 로직이 수행될 것 같지는 않아보여요 !
function Button({ children, size }: { children: ReactNode; size: number }) { | ||
return ( | ||
<> | ||
<S.Cta size={size}>{children}</S.Cta> | ||
</> | ||
); | ||
} |
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.
React에서 제공하는 HTML type
을 사용해보시는건 어떨까요?
다음과 같이 리액트에서 제공하는 Attributes를 사용할 수도 있습니다:
import cn from 'classnames';
import { ButtonHTMLAttributes } from 'react';
interface Props extends ButtonHTMLAttributes<HTMLButtonElement> {
variant?: 'primary' | 'secondary' | 'none';
}
export default function MelonButton({ className, variant, ...rest }: 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.
상준님 코드에서는 다음과 같이 적용해볼 수 있어요:
type ButtonProps = { size: 'lg' | 'md' | 'sm' } & ButtonHTMLAttributes<HTMLButtonElement>;
function Button({ children, size }: ButtonProps) {
return (
<S.Cta size={size}>{children}</S.Cta>
);
}
|
||
const { url, description } = item; | ||
|
||
const createdText = `${createdAt.time} ${createdAt.result} ago`; |
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 createdText = `${createdAt.time} ${createdAt.result} ago`; | |
const createdText = useMemo(() =>`${createdAt.time} ${createdAt.result} ago`, [createdAt]); |
@@ -1,18 +1,19 @@ | |||
import styled from 'styled-components'; | |||
|
|||
export const FolderName = styled.span` | |||
export const FolderName = styled.span<{ $select: string | 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.
하단 조건부를 보면 boolean
으로 취급되는 경우가 없는 것 같아요:
export const FolderName = styled.span<{ $select: string | boolean }>` | |
export const FolderName = styled.span<{ $select: boolean }>` |
또한, boolean
과 string
이 유니온 타입으로 지정될 일은 흔치 않을 것으로 보입니다 😃
toggleModal, | ||
}: { | ||
link: Folders; | ||
setFolderName: React.Dispatch<React.SetStateAction<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.
굳굳 ! 리액트 Dispatch
타입을 적절하게 사용하셨군요 👍
상준님 정말 수고 많으셨습니다 ! 주말에 주강사로 활동하고 있으니, 궁금한거 있으시면 편하게 들어와서 물어보세요 ㅎㅎㅎ |
요구사항
기본
심화
주요 변경사항
스크린샷
멘토에게