Simple example showing how to add MQTT to your React app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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