Skip to content
Discussion options

You must be logged in to vote

I have a hook that wraps react query, and currently it only unsubscribes the websocket when react-query attempts to open a new one, I am still determining when to unsubscribe.

  • If I do it on unmount, then these queries can't be cached because being cached means they won't open a new connection anymore.
  • Also, if I put the connection in a useEffect hook outside of the query, if I use a query in multiple places then that spawns excess connections. I want the connection tied to the query key specifically.
  • If I subscribe when react-query deems it as stale, then I am closing/opening a lot of connections for no reason.
  • If I cache the data for too long, then I am going to end up having connection…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@TkDodo
Comment options

@Mike-Sinistralis
Comment options

@TkDodo
Comment options

@Mike-Sinistralis
Comment options

@Mike-Sinistralis
Comment options

Answer selected by Mike-Sinistralis
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