Closed manemao closed 2 years ago
Although there is a way for custom unsubscription with useStompClient()
:
const sub = useStompClient().subscribe('/...', callback)
sub.unsubscribe()
didn't knew that when submitting this issue, closing it now.
Hello @manemao!
The preferred way to do this would be in a declarative way, by changing the list of topics you want to subscribe to provided to the useSubscription hook. I just tested this and discovered a bug preventing this use case due to an oversight on my end. I published a fix for this, and included an additional example showing how you can dynamically subscribe/unsubscibe:
The way you describe in your comment will work absolutely fine too, if you want to achive this in an imperative way. Note however that you should only use this inside an effect and you are responsible for correctly calling the cleanup function yourself too.
Hi @fallobst22 ! thanks for immediate fix and comment on the issue 🙏
besides when "parent component is unmounting" there is situations that you need to unsubscribe a specific destination. i didn't find fancy way to do so with this library. one clean way, for example, could be returning an array of subscription objects as
useSubscription
hook output.or maybe there is a clean way to do it and it just not well documented. thanks anyway for lib 👍