react-use-mqtt
v1.1.6
Published
React Library for interfacing with the Paho-MQTT Library using hooks
Downloads
8
Readme
React Use MQTT
Installation
npm install react-use-mqtt
# or
yarn add react-use-mqtt
# or
pnpm add react-use-mqtt
Usage
import React from "react";
import { MqttProvider } from "react-use-mqtt";
export default function App() {
return (
<MqttProvider
host="localhost"
port="9001"
options={{
clientId: "react-use-mqtt",
username: "admin",
password: "admin",
}}
>
<YourApp />
</MqttProvider>
);
}
import React from "react";
import { useMqttState } from "react-use-mqtt";
export default function YourApp() {
const { connectionStatus } = useMqttState();
return <div>{connectionStatus}</div>;
}
import React from "react";
import { useSubscription } from "react-use-mqtt";
export default function YourApp() {
const { client, topic, message, connectionStatus, error } = useSubscription("topic");
return <div>{message.message}</div>;
}
Building
pnpm build
License
MIT © sebasptsch
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.