Skip to content

Instantly share code, notes, and snippets.

@jenschr
Created November 2, 2021 11:52
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/73050068a784862ef83b006d30862337 to your computer and use it in GitHub Desktop.
Save jenschr/73050068a784862ef83b006d30862337 to your computer and use it in GitHub Desktop.
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