Skip to content

Commit d716159

Browse files
authored
enhance: Use controller.getResponseMeta() in hooks (#3398)
1 parent abacd36 commit d716159

File tree

8 files changed

+20
-10
lines changed

8 files changed

+20
-10
lines changed

.changeset/angry-spoons-play.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@data-client/react': patch
3+
---
4+
5+
Use controller.getResponseMeta() in hooks
6+
7+
No behavior change, just anticipating API updates to controller

packages/react/src/hooks/useCache.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default function useCache<
4040

4141
// Compute denormalized value
4242
const { data, expiryStatus, expiresAt, countRef } = useMemo(() => {
43-
return controller.getResponse(endpoint, ...args, state);
43+
return controller.getResponseMeta(endpoint, ...args, state);
4444
// eslint-disable-next-line react-hooks/exhaustive-deps
4545
}, [
4646
cacheResults,
@@ -76,7 +76,8 @@ export default function useCache<
7676
// if useSuspense() would suspend, don't include entities from cache
7777
if (loading) {
7878
if (!endpoint.schema) return undefined;
79-
return controller.getResponse(endpoint, ...args, {
79+
// TODO: use getResponse() once it just returns data
80+
return controller.getResponseMeta(endpoint, ...args, {
8081
...state,
8182
entities: {},
8283
}).data as any;

packages/react/src/hooks/useDLE.native.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export default function useDLE<
8282
// Compute denormalized value
8383
// eslint-disable-next-line prefer-const
8484
let { data, expiryStatus, expiresAt, countRef } = useMemo(() => {
85-
return controller.getResponse(endpoint, ...args, state);
85+
return controller.getResponseMeta(endpoint, ...args, state);
8686
// eslint-disable-next-line react-hooks/exhaustive-deps
8787
}, [
8888
cacheResults,
@@ -123,7 +123,8 @@ export default function useDLE<
123123
// if useSuspense() would suspend, don't include entities from cache
124124
if (loading) {
125125
if (!endpoint.schema) return undefined;
126-
return controller.getResponse(endpoint, ...args, {
126+
// TODO: use getResponse() once it just returns data
127+
return controller.getResponseMeta(endpoint, ...args, {
127128
...state,
128129
entities: {},
129130
}).data as any;

packages/react/src/hooks/useDLE.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default function useDLE<
8080
// Compute denormalized value
8181
// eslint-disable-next-line prefer-const
8282
let { data, expiryStatus, expiresAt, countRef } = useMemo(() => {
83-
return controller.getResponse(endpoint, ...args, state);
83+
return controller.getResponseMeta(endpoint, ...args, state);
8484
// eslint-disable-next-line react-hooks/exhaustive-deps
8585
}, [
8686
cacheResults,
@@ -110,7 +110,8 @@ export default function useDLE<
110110
// if useSuspense() would suspend, don't include entities from cache
111111
if (loading) {
112112
if (!endpoint.schema) return undefined;
113-
return controller.getResponse(endpoint, ...args, {
113+
// TODO: use getResponse() once it just returns data
114+
return controller.getResponseMeta(endpoint, ...args, {
114115
...state,
115116
entities: {},
116117
}).data as any;

packages/react/src/hooks/useFetch.native.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export default function useFetch<
5959

6060
// Compute denormalized value
6161
const { expiryStatus, expiresAt } = useMemo(() => {
62-
return controller.getResponse(endpoint, ...args, state);
62+
return controller.getResponseMeta(endpoint, ...args, state);
6363
// eslint-disable-next-line react-hooks/exhaustive-deps
6464
}, [
6565
cacheResults,

packages/react/src/hooks/useFetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default function useFetch<
5757

5858
// Compute denormalized value
5959
const { expiryStatus, expiresAt } = useMemo(() => {
60-
return controller.getResponse(endpoint, ...args, state);
60+
return controller.getResponseMeta(endpoint, ...args, state);
6161
// eslint-disable-next-line react-hooks/exhaustive-deps
6262
}, [
6363
cacheResults,

packages/react/src/hooks/useSuspense.native.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export default function useSuspense<
6464

6565
// Compute denormalized value
6666
const { data, expiryStatus, expiresAt, countRef } = useMemo(() => {
67-
return controller.getResponse(endpoint, ...args, state);
67+
return controller.getResponseMeta(endpoint, ...args, state);
6868
// eslint-disable-next-line react-hooks/exhaustive-deps
6969
}, [
7070
cacheResults,

packages/react/src/hooks/useSuspense.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export default function useSuspense<
6161

6262
// Compute denormalized value
6363
const { data, expiryStatus, expiresAt, countRef } = useMemo(() => {
64-
return controller.getResponse(endpoint, ...args, state);
64+
return controller.getResponseMeta(endpoint, ...args, state);
6565
// eslint-disable-next-line react-hooks/exhaustive-deps
6666
}, [
6767
cacheResults,

0 commit comments

Comments
 (0)