WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@siduck
Copy link
Contributor

@siduck siduck commented Dec 4, 2025

Closes: #26

Usage

const resp = createResources()

unMounted(() => {
     resp.abort()
})
Screen.Recording.2025-12-04.at.12.00.34.PM.mov

To those who want to do this automatically , just make a wrapper over createResources()

const wrapperFetch = (opts) => {
  const resp = createResource(opts)
  onUnmounted(resp.abort)
  return resp
}

@siduck siduck changed the title feat(createResources): about method to cancel ongoing fetch requests feat(createResources): abort method to cancel ongoing fetch requests Dec 4, 2025
@siduck siduck requested a review from NagariaHussain December 4, 2025 06:34
@NagariaHussain
Copy link
Collaborator

NagariaHussain commented Dec 4, 2025

The dev has to write these unmount wrappers manually? 👀

Can we do a plugin (or hook) or something which automatically aborts? I think it should be possible at least for route changes.

@siduck
Copy link
Contributor Author

siduck commented Dec 9, 2025

The dev has to write these unmount wrappers manually? 👀

Can we do a plugin (or hook) or something which automatically aborts? I think it should be possible at least for route changes.

hm so the user can just use this wrapper of createResource

import { abortableFetch } from "frappe-ui"

const posts = abortableFetch( { url } )

@NagariaHussain
Copy link
Collaborator

That could work too. But since createResource is also a hook, maybe a config like "abortOnUnmount"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cancel ongoing fetch requests in resources when component is unmounted

3 participants