Skip to content

Commit b8a595b

Browse files
committed
fix: App 부분 추가, queryKey url, heroId 분리
1 parent 5303c68 commit b8a595b

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
26. [사용자 경험(UX)을 올려주는 Optimistic Updates(낙관적 업데이트)](#optimistic-update)
5151
27. [에러가 발생했을 때 Fallback UI를 선언적으로 보여주기 위한 ErrorBoundary + useQueryErrorResetBoundary](#usequeryerrorresetboundary)
5252
28. [서버 로딩중일 때 Fallback UI를 선언적으로 보여주기 위한 Suspense](#suspense)
53-
29. [앱의 기본 쿼리를 설정하는 Default Query Function](#default-query-function)
53+
29. [앱 전체에 동일한 쿼리 함수를 공유하는 Default Query Function](#default-query-function)
5454
30. [리액트 쿼리에 타입스크립트 적용](#react-query-typescript)
5555

5656
<br />
@@ -1263,16 +1263,24 @@ function App() {
12631263
```jsx
12641264
// 기본 쿼리 함수
12651265
const getSuperHero = async ({ queryKey }: any) => {
1266-
return await axios.get(`http://localhost:4000/${queryKey[0]}`);
1266+
const heroId = queryKey[1];
1267+
return await axios.get(`http://localhost:4000/superheroes/${heroId}`);
12671268
};
12681269

12691270
const queryClient = new QueryClient({
12701271
defaultOptions: {
12711272
queries: {
12721273
queryFn: getSuperHero,
1274+
// ...queries options
12731275
},
12741276
},
12751277
});
1278+
1279+
function App() {
1280+
return (
1281+
<QueryClientProvider client={queryClient}>{/* ... */}</QueryClientProvider>
1282+
);
1283+
}
12761284
```
12771285
12781286
- `QueryClient`에 앱 전체에서 사용할 쿼리 함수를 지정해 준다.

0 commit comments

Comments
 (0)