Skip to content

Commit 50b70fa

Browse files
committed
fix: show previous data while loading new one
1 parent ac6da2c commit 50b70fa

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/useQuery.ts

+9
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ export function useQuery<
9696
? 'cache-first'
9797
: actualCachePolicy;
9898

99+
const lastResult = React.useRef();
100+
99101
const watchQueryOptions: WatchQueryOptions<TVariables> = useMemo(
100102
() =>
101103
compact({
@@ -144,6 +146,12 @@ export function useQuery<
144146
};
145147
}
146148

149+
if (result.loading) {
150+
data = {
151+
...(lastResult.current || {}).data,
152+
};
153+
}
154+
147155
return {
148156
data,
149157
error:
@@ -161,6 +169,7 @@ export function useQuery<
161169
},
162170
[shouldSkip, responseId, observableQuery]
163171
);
172+
lastResult.current = currentResult;
164173

165174
useEffect(
166175
() => {

0 commit comments

Comments
 (0)