Skip to content

Manual Query Cancellation not working #7962

Discussion options

You must be logged in to vote

Hello

In your example, there is 2 errors for me:

  • you don't get the signal from queryFn parameter:
const { isLoading, isError, isSuccess, data, error } = useQuery({
        queryKey: ['todos'],
        // Get the signal to pass to the fetch
        queryFn: async ({ signal }) => {
            try {
                const resp = await fetch(`https://jsonplaceholder.typicode.com/posts?_page=5&_limit=10`, { signal });
                if (!resp.ok) {
                    throw new Error('Network response was not ok');
                }
                return resp.json();
            } catch (err) {
                throw err;
            }
        },
    });
  • the API for queryClient.cancelQueries

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@SujithKannaa98
Comment options

@romain-trotard
Comment options

Answer selected by TkDodo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants