mqtt-react-hooks icon indicating copy to clipboard operation
mqtt-react-hooks copied to clipboard

is it a problem since it never unsubscribe subscribed message? thanks.

Open postgetme opened this issue 4 years ago • 3 comments

postgetme avatar Sep 21 '21 10:09 postgetme

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.

postgetme avatar Sep 21 '21 11:09 postgetme

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]);`

NDallaRiva avatar Jan 17 '22 08:01 NDallaRiva

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.

sfeu avatar Jun 10 '22 10:06 sfeu