Skip to content

Instantly share code, notes, and snippets.

@jenschr
Created November 2, 2021 14:41
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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