# react-use-mqtt

> React Library for interfacing with the Paho-MQTT Library using hooks

Latest version **1.1.6** (published 2024-07-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-use-mqtt
pnpm add react-use-mqtt
yarn add react-use-mqtt
bun add react-use-mqtt
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.6 |
| Published | 2024-07-10 |
| First published | 2023-02-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 40.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Sebastian Pietschner |
| Maintainers | sebasptsch |

## Links

- npm: https://www.npmjs.com/package/react-use-mqtt
- Repository: https://github.com/sebasptsch/react-use-mqtt
- Homepage: https://github.com/sebasptsch/react-use-mqtt#readme
- Issues: https://github.com/sebasptsch/react-use-mqtt/issues
- npm.io page: https://npm.io/package/react-use-mqtt

## Dependencies (5)

- [react](https://npm.io/package/react.md) ^18.2.0
- [paho-mqtt](https://npm.io/package/paho-mqtt.md) ^1.1.0
- [react-dom](https://npm.io/package/react-dom.md) ^18.2.0
- [mqtt-pattern](https://npm.io/package/mqtt-pattern.md) ^2.1.0
- [eventemitter3](https://npm.io/package/eventemitter3.md) ^5.0.1

## Recent versions

- 1.1.6 (latest) — 2024-07-10
- 1.1.5 — 2024-04-30
- 1.1.4 — 2024-04-11
- 1.1.3 — 2024-02-07
- 1.1.2 — 2024-02-07
- 1.1.1 — 2024-02-04
- 1.1.0 — 2024-02-02
- 1.0.4 — 2023-02-04
- 1.0.3 — 2023-02-03
- 1.0.2 — 2023-02-03
- 1.0.1 — 2023-02-02
- 1.0.0 — 2023-02-02

## README

## React Use MQTT

[![Publish Package to npmjs](https://github.com/sebasptsch/react-use-mqtt/actions/workflows/publish.yml/badge.svg)](https://github.com/sebasptsch/react-use-mqtt/actions/workflows/publish.yml)

---

## Installation

```bash
npm install react-use-mqtt
# or
yarn add react-use-mqtt
# or
pnpm add react-use-mqtt
```

## Usage

```jsx
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>
  );
}
```

```jsx
import React from "react";

import { useMqttState } from "react-use-mqtt";

export default function YourApp() {
  const { connectionStatus } = useMqttState();

  return <div>{connectionStatus}</div>;
}
```

```jsx
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

```bash
pnpm build
```

## License

MIT © [sebasptsch](https://github.com/sebasptsch)

## Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

---
_Source: https://npm.io/package/react-use-mqtt · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
