[오영택] sprint 5,9#704
Open
Programmeryeongtaek wants to merge 62 commits intocodeit-bootcamp-frontend:mainfrom
Hidden character warning
The head ref may contain hidden characters: "Next.js-\uc624\uc601\ud0dd-sprint11"
Open
[오영택] sprint 5,9#704Programmeryeongtaek wants to merge 62 commits intocodeit-bootcamp-frontend:mainfrom
Programmeryeongtaek wants to merge 62 commits intocodeit-bootcamp-frontend:mainfrom
Conversation
| }) | ||
|
|
||
| try { | ||
| const res = await fetch( |
Collaborator
There was a problem hiding this comment.
공통 api 함수가 하나 있으면 좋겠네요.
아래 baseApi 함수를 확인해주시면 됩니다.
type BaseApiMethods = "get" | "post" | "put" | "patch" | "delete";
type BaseApiCommonArgs = {
url: URL;
headers: RequestInit["headers"];
};
interface BaseApiNonBodyArgs extends BaseApiCommonArgs {
method: "get" | "delete";
}
interface BaseApiWithBodyArgs extends BaseApiCommonArgs {
method: "post" | "put" | "patch";
body: RequestInit["body"];
}
type BaseApiArgs<T extends BaseApiMethods> = T extends "get"
? BaseApiNonBodyArgs
: BaseApiWithBodyArgs;
type BaseApiArgsType = BaseApiNonBodyArgs | BaseApiWithBodyArgs;
type BaseApiFunc = <T extends BaseApiArgsType["method"]>(
data: BaseApiArgs<T>
) => Promise<Response>;
const API_BASE_URL = "https://panda-market-api.vercel.app";
export const baseApi: BaseApiFunc = async ({ url, ...args }) => {
try {
const timeout = AbortSignal.timeout(5000); // timeout 5초
return await fetch(`${API_BASE_URL}/${url}`, { ...args, signal: timeout });
}
catch(err) {
// 실패했을 때 공통적으로 return 해줘야 할 응답값
}
};|
|
||
| const viewportWidth = useViewport(); | ||
|
|
||
| useEffect(() => { |
Collaborator
There was a problem hiding this comment.
useEffect는 react의 여러 라이프사이클을 핸들링 할 수 있는 훅입니다.
그래서 내부에서 추가적으로 호출해줘야되는 함수들이 늘어날 수 있기 때문에, 함수의 구현부(fetchBestArticles)는 useEffect 외부로 빼주시면 좋습니다.
Collaborator
There was a problem hiding this comment.
전반적으로 기본적인 기능 구현사항이라 크게 커멘트를 남길 필요는 없을 듯 합니다.
그리고 현재 각 컴포넌트에서 api 호출 후, 응답 데이터를 state로 관리하여 ui 렌더링 시키는 구조가 많은 데,
setLoading(true) -> api response -> setLoading(false) -> setData 이런 반복적인 코드가 보이네요.
type UseApiArgs {
// .....
}
// useApi 내부에서 실제 api 콜을 하는 함수
type Fetcher {
// ....
}
const useApi = <T>(fetcher: Fetcher) => {
const [data, setData] = useState<T>();
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState();
const trigger = async () => {
try{
setIsLoading(true);
const result = await fetcher();
setIsLoading(false;
setData(result)
}
catch(err) {
setError(err);
}
}
return {
data, isLoading, error, trigger
}
}
// ./page or ./component
const fetcher = () => {
return fetch("", {});
}
const DummyComponent = () => {
const {data, isLoading, error, trigger} = useApi(fetcher);
return (
<>
{isLoading && <Loading />}
{!isLoading && <div>{JSON.stringify(data)}</div>
</>
)
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
요구사항
기본
<미션 9>
<미션 5> 넥스트로 구현
심화
<미션 9>
<미션 5>
주요 변경사항
스크린샷
멘토에게
-tailwind 동적 CSS 구현방법을 잘 모르겠습니다...