Open postgetme opened 3 years ago
The page 2 will receive also the messages of page 1 subscription.
I think this is not the best behavior. This can be improved adding the unsubscribe action In useSubscription.tsx in line 36 we have the useEffect hook `useEffect(() => { if (client?.connected) { subscribe();
client.on('message', callback);
}
return () => {
client?.off('message', callback);
// Add unsubscription here, something like
client?.unsubscribe(topic)
};
}, [callback, client, subscribe]);`
If individual react components are subscribing ("useSubscription") for specific topics and later on are longer rendered - it would be helpful to support an unsubscribe option to reduce bandwidth.
for example I have 2 pages which with different subscriptions, I open page 1 then open page 2, in the page 2 will receive all message on the bottom.