Skip to content

Support for async cleanup functions? #98

@chmac

Description

@chmac

I read #6 and then #7. I saw that handling streams / observables doesn't make sense here, there are other hooks.

My situation is a little different. I'm using nostr, where I create a subscription over a websocket, and then I need to unsubscribe when my component is unmounted. Is there any support for running an async cleanup function in react-async-hook?

Here's an example of what I imagine:

const fetchAndReturnCleanupFunction = async () => {
  const unsubscribeFunction = await doSomeSubscribe();
  return unusbscribeFunction
}

Where I want unsubscribeFunction to be called once my component is unmounted. I don't think that's currently possible with useAsync() right?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions