Skip to content

Commit d1adaa0

Browse files
committed
refactor: remove cancel method as it no longer exists
use signal in playground example instead of cancel fn
1 parent 28c9291 commit d1adaa0

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

examples/playground/src/index.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ function Todos({ initialFilter = "", setEditingIndex }) {
181181

182182
const { status, data, isFetching, error, failureCount, refetch } = useQuery(
183183
["todos", { filter }],
184-
() => fetchTodos({ filter })
184+
fetchTodos
185185
);
186186

187187
return (
@@ -370,9 +370,16 @@ function AddTodo() {
370370
);
371371
}
372372

373-
function fetchTodos({ filter } = {}) {
373+
function fetchTodos({ signal, queryKey: [, { filter }] }) {
374374
console.info("fetchTodos", { filter });
375-
const promise = new Promise((resolve, reject) => {
375+
376+
if (signal) {
377+
signal.addEventListener("abort", () => {
378+
console.info("cancelled", filter);
379+
});
380+
}
381+
382+
return new Promise((resolve, reject) => {
376383
setTimeout(() => {
377384
if (Math.random() < errorRate) {
378385
return reject(
@@ -382,10 +389,6 @@ function fetchTodos({ filter } = {}) {
382389
resolve(list.filter((d) => d.name.includes(filter)));
383390
}, queryTimeMin + Math.random() * (queryTimeMax - queryTimeMin));
384391
});
385-
386-
promise.cancel = () => console.info("cancelled", filter);
387-
388-
return promise;
389392
}
390393

391394
function fetchTodoById({ id }) {

0 commit comments

Comments
 (0)