VictorHAS / mqtt-react-hooks

ReactJS library for Pub/Sub communication with an MQTT broker using Hooks
MIT License
91 stars 28 forks source link

TypeError: Cannot read properties of undefined (reading 'topic') #38

Open kitar-kks opened 2 years ago

kitar-kks commented 2 years ago

I got a error from use Subscription example ( TypeError: Cannot read properties of undefined (reading 'topic') )

`import React from 'react';

import { useSubscription } from 'mqtt-react-hooks';

export default function Status() { /* Message structure:

</> ); }` How can I fix it

thomasklingel commented 2 years ago

Just try {topic:${message?.topic} - message: ${message?.message}} It will print : "topic: undefined - message: undefined" if your message object is empty and it's going to be re-rendered each time a message arrive without error