Skip to content

Instantly share code, notes, and snippets.

@jenschr
Created November 2, 2021 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jenschr/44924760890aab65a4dcb2b4cd1e89c5 to your computer and use it in GitHub Desktop.
Save jenschr/44924760890aab65a4dcb2b4cd1e89c5 to your computer and use it in GitHub Desktop.
import React from 'react';
import { useSubscription } from 'mqtt-react-hooks';
export default function Subscriber() {
/* Message structure:
* topic: string
* message: string
*/
const { message } = useSubscription([
'test',
]);
const renderMessage = () => {
if(message){
return <span>{message.topic} - {message.message}</span>
} else{
return <span>none</span>
}
}
return (
<>
<div style={{ display: 'flex', flexDirection: 'column' }}>
{renderMessage()}
</div>
</>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment