Skip to content

Instantly share code, notes, and snippets.

@jenschr
Created Nov 2, 2021
Embed
What would you like to do?
Simple example showing how to add MQTT to your React app
import logo from './logo.svg';
import './App.css';
import { Connector } from 'mqtt-react-hooks';
import Status from './Status';
const mqttOptions = {
username: 'username',
password: 'password', // Passwords are buffers
}
function App() {
return (
<Connector brokerUrl="ws://161.35.167.71:8000/mqtt" options={mqttOptions}>
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
<Status />
</header>
</div>
</Connector>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment