Skip to content

Commit 430331b

Browse files
Katarina Antonkaciakmaciak
authored andcommitted
refactor: refactor onData callback being called by useEffect
The `onSuccess` option has breaking changes in v4 and behaves differently resolves #67
1 parent b650b88 commit 430331b

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/use-infinite-subscription.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,19 @@ export function useInfiniteSubscription<
199199
refetchOnMount: true,
200200
refetchOnWindowFocus: false,
201201
refetchOnReconnect: false,
202-
onSuccess: options.onData,
203202
onError: (error: TError) => {
204203
clearErrors();
205204
options.onError && options.onError(error);
206205
},
207206
});
208207

208+
useEffect(() => {
209+
if (queryResult.isSuccess) {
210+
options.onData?.(queryResult.data);
211+
}
212+
// eslint-disable-next-line react-hooks/exhaustive-deps
213+
}, [queryResult.data]);
214+
209215
useEffect(() => {
210216
return function cleanup() {
211217
// Fixes unsubscribe

src/use-subscription.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,19 @@ export function useSubscription<
135135
refetchOnMount: true,
136136
refetchOnWindowFocus: false,
137137
refetchOnReconnect: false,
138-
onSuccess: options.onData,
139138
onError: (error: TError) => {
140139
clearErrors();
141140
options.onError && options.onError(error);
142141
},
143142
});
144143

144+
useEffect(() => {
145+
if (queryResult.isSuccess) {
146+
options.onData?.(queryResult.data);
147+
}
148+
// eslint-disable-next-line react-hooks/exhaustive-deps
149+
}, [queryResult.data]);
150+
145151
useEffect(() => {
146152
return function cleanup() {
147153
// Fixes unsubscribe

0 commit comments

Comments
 (0)