-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feature/main page API 연동 완료 #16
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2b9f3ca
feat: value 값 영어로 변경
2NNS-V 515ac69
chore: 메인 이미지 배경 제거
2NNS-V 6f96cd1
feat: Axios 훅 추가
2NNS-V b28b0d9
feat: 전체 통계 API 연결
2NNS-V 26dc6ca
feat: 통계페이지 API 연결
2NNS-V 508574d
refact: useAxios 타입 명시
2NNS-V 88c663a
fix: Axios 타입 에러 해결
2NNS-V 767c3d0
fix: renderData 함수 추가 및 타입 설정
2NNS-V 1a68b0a
fix: 순위 받아오는 함수 추가 및 타입 지정
2NNS-V a347d62
refact: import 코드 수정
2NNS-V 240344d
Merge branch 'feature/main-page' into HEAD
2NNS-V File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from "react"; | ||
|
||
import axios, { AxiosRequestConfig } from "axios"; | ||
|
||
const instance = axios.create({ | ||
baseURL: "https://api.dongbti.com", | ||
withCredentials: true, | ||
}); | ||
|
||
export default function useAxios<T>(config: AxiosRequestConfig, dependencies: ReadonlyArray<any> = []) { | ||
const [data, setData] = React.useState<T | null>(null); | ||
const [loading, setLoading] = React.useState<boolean>(false); | ||
const [error, setError] = React.useState<string | null>(null); | ||
|
||
React.useEffect(() => { | ||
const fetchData = async () => { | ||
setLoading(true); | ||
try { | ||
const response = await instance(config); | ||
setData(response.data); | ||
console.log(response.data); | ||
} catch (err: any) { | ||
if (axios.isAxiosError(err)) { | ||
setError(err.message || "Something went wrong"); | ||
} else { | ||
setError("Something went wrong"); | ||
} | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
fetchData(); | ||
}, dependencies); | ||
|
||
return { data, loading, error }; | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
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.
selectedMajor 에 인문대학에 해당하는 값을 기본적으로 넣는것 보다, null 과 같은 값을 넣어두고,
department 를 선택하지 않은 경우, 에러 메시지를 띄우는 것이 좋아보입니다!
그리고 상태에 해당하는 값또한
string
보다는 enum 타입으로 따로 분리하면 좋을 것 같아요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.
혹시
enum
타입을 사용하는 이유가 있을까요? API를 보낼 때마다,setDepartment()
마다 DropDown의value
(string)을 아래처럼 선언된 Department 타입으로 변경해야 하는데, enum을 사용할 필요가 있을까요? 아니면 서버에서 받기 쉬워서 그런건가요?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.
사실 서버에서 받기 쉬운것보다 enum 타입으로 선언하면
Department.Humanities
로 IDE 나 코드 편집기에서 자동완성을 해주기 때문에,,, 자잘한 오류를 방지하기 위해서 주로 사용합니다!여러 군데에서 해당 department 의 값을 사용할때 사용하면 좋을것 같아요~