-
Notifications
You must be signed in to change notification settings - Fork 0
[UNI-98] feat : Tanstack Query 도입 및 커스텀 Fetch 모듈 생성 #38
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d66a087
[UNI-102] feat : tanstack-Query 라이브러리 설치 및 Lint 추천 설정 적용
dgfh0450 6b3155c
[UNI-103] feat : Custom fetch 함수 생성 및 Get 메소드 생성 및 예시
dgfh0450 dcb276a
[UNI-103] feat : Post 메소드 추가 및 CustomFetch 이름 변경 => Fetch
dgfh0450 7cbbe0a
[UNI-103] feat : GET, POST, PUT 제네릭 타입 지정
dgfh0450 964f5a1
[UNI-98] feat : Lint 적용
dgfh0450 b5561a4
Merge branch 'fe' into feat/UNI-98
dgfh0450 23d4a96
[UNI-98] refactor : Fetch 함수 인스턴스화하여 각 메소드 export 적용
dgfh0450 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| export default function Fetch() { | ||
| const baseURL = import.meta.env.VITE_REACT_SERVER_BASE_URL; | ||
|
|
||
| const get = async <T>(url: string, params?: Record<string, string | number | boolean>): Promise<T> => { | ||
| const paramsURL = new URLSearchParams( | ||
| Object.entries(params || {}).map(([key, value]) => [key, String(value)]), | ||
| ).toString(); | ||
|
|
||
| const response = await fetch(`${baseURL}${url}?${paramsURL}`, { | ||
| method: "GET", | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error(`${response.status}-${response.statusText}`); | ||
| } | ||
|
|
||
| return response.json(); | ||
| }; | ||
|
|
||
| const post = async <T, K>(url: string, body?: Record<string, K>): Promise<T> => { | ||
| const response = await fetch(`${baseURL}${url}`, { | ||
| method: "POST", | ||
| body: JSON.stringify(body), | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error(`${response.status}-${response.statusText}`); | ||
| } | ||
|
|
||
| return response.json(); | ||
| }; | ||
|
|
||
| const put = async <T, K>(url: string, body?: Record<string, K>): Promise<T> => { | ||
| const response = await fetch(`${baseURL}${url}`, { | ||
| method: "PUT", | ||
| body: JSON.stringify(body), | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error(`${response.status}-${response.statusText}`); | ||
| } | ||
|
|
||
| return response.json(); | ||
| }; | ||
|
|
||
| return { | ||
| get, | ||
| post, | ||
| put, | ||
| }; | ||
| } | ||
|
|
||
| const { get, post, put } = Fetch(); | ||
| export { get as getFetch, post as postFetch, put as putFetch }; | ||
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.
제네릭을 잘 사용해서 만드신 것 같습니다! 혹시 Fetch를 하나의 Instance로 만들어서 사용하는 방법은 어떨까요??
const { get, post, put } = Fetch();
이러면 하나의 객체로 여러번 돌려쓸 수 있을거 같아서 좋을 거 같습니다.