取消查询
默认行为
使用 fetch
fetchconst query = useQuery({
queryKey: ['todos'],
queryFn: async ({ signal }) => {
const todosResponse = await fetch('/todos', {
// 将 signal 传递给一次 fetch
signal,
})
const todos = await todosResponse.json()
const todoDetails = todos.map(async ({ details }) => {
const response = await fetch(details, {
// 或传递给多次 fetch
signal,
})
return response.json()
})
return Promise.all(todoDetails)
},
})使用 axios v0.22.0+
axios v0.22.0+使用低于 v0.22.0 版本的 axios
axios使用 XMLHttpRequest
XMLHttpRequest使用 graphql-request
graphql-request使用低于 v4.0.0 版本的 graphql-request
graphql-request手动取消
取消选项(Cancel Options)
取消选项(Cancel Options)局限性
最后更新于