The useEffect cleanup prematurely closes the MQTT client.
The issue involves the `useEffect` cleanup in the `useMqtt` hook closing the MQTT client when the component unmounts, making it unusable on other pages. The fix requires modifying the cleanup logic to avoid premature closure. No major blockers are apparent.
the useEffect return cause client closure and so the mqtt client is not usable in the other pages.
return () => {
if (client) {
topicHandlers.forEach((th) => {
client.unsubscribe(th.topic);
});
client.end();
}
};
mqtt.js
No response
No response
the useEffect return cause client closure and so the mqtt client is not usable in the other pages.
the useEffect return cause client closure and so the mqtt client is not usable in the other pages.
Use the example
Claim this issue to let others know you're working on it. You'll earn 10 points when you complete it!