Replies: 4 comments 7 replies
-
|
+) 추가 안건 : 추석 연휴에 스터디 일정 (10/5, 12일) |
Beta Was this translation helpful? Give feedback.
-
|
8장 ACL 사용법 부분에서 백엔드에서 오는 nullish한 값이나 undefined 필드를 처리할 때, transfomer 파일에서 처리를 하고 UI 담당 컴포넌트에서는 단순히 이를 사용한다고 하는데, 다른 분들께서는 어떻게 하시는지 궁금합니다.
|
Beta Was this translation helpful? Give feedback.
-
|
리액트 쿼리를 사용하지 않아도 fetch 용 함수를 별도의 훅으로 관리하시나요?? |
Beta Was this translation helpful? Give feedback.
-
|
의존성 역전 원칙의 예시 중 하나로 API 호출 인터페이스도 적용될 수 있다고 생각합니다. import { ApiError } from "../types/apiError";
export class ApiClient {
private baseUrl: string;
constructor(url: string) {
this.baseUrl = url;
}
private buildUrl(
endpoint: string,
queryParams?: Record<string, string | number | boolean>
): string {
const url = new URL(endpoint, this.baseUrl);
if (queryParams) {
Object.entries(queryParams).forEach(([key, value]) => {
url.searchParams.append(key, value.toString());
});
}
return url.toString();
}
private async request(
method: string,
endpoint: string,
options?: RequestInit,
body?: Record<string, unknown>,
queryParams?: Record<string, string | number | boolean>
) {
const url = this.buildUrl(endpoint, queryParams);
try {
const response = await fetch(url, {
method,
headers: {
"Content-Type": "application/json",
...options?.headers,
},
body: body ? JSON.stringify(body) : undefined,
...options,
});
const result = await response.json();
if (!response.ok) {
throw new ApiError({
code: result?.code || "HTTP_ERROR",
message:
result?.message ||
`HTTP ${response.status}: ${response.statusText}`,
data: result?.data,
isSuccess: result?.isSuccess || false,
});
}
return result;
} catch (error) {
console.warn("Error parsing JSON response:", error);
throw new Error("Error parsing JSON response");
}
}
public get(
endpoint: string,
queryParams?: Record<string, string | number | boolean>,
options?: RequestInit
) {
return this.request("GET", endpoint, options, undefined, queryParams);
}
public post(
endpoint: string,
body?: Record<string, unknown> | undefined,
options?: RequestInit
) {
return this.request("POST", endpoint, options, body);
}
public put(
endpoint: string,
body?: Record<string, unknown>,
options?: RequestInit
) {
return this.request("PUT", endpoint, options, body);
}
public delete(endpoint: string, options?: RequestInit) {
return this.request("DELETE", endpoint, options);
}
}
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
8장_리액트 데이터 관리
9장_리액트 설계 원칙 적용
10징_합성 패턴
위 주제에 맞는 혹은 나누고 싶은 주제에 대해 자유롭게 남겨주세요~!
Beta Was this translation helpful? Give feedback.
All reactions