https://github.com/rhdeck/react-aws-iot
Hooks provider for AWS IOT (MQTT) service
https://github.com/rhdeck/react-aws-iot
Last synced: 5 months ago
JSON representation
Hooks provider for AWS IOT (MQTT) service
- Host: GitHub
- URL: https://github.com/rhdeck/react-aws-iot
- Owner: rhdeck
- License: mit
- Created: 2019-05-23T21:03:46.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-03T10:45:51.000Z (over 3 years ago)
- Last Synced: 2025-08-09T14:18:33.896Z (11 months ago)
- Language: JavaScript
- Size: 448 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# react-aws-iot
## Usage
1. Set up the provider high in your tree. No props required
```js
import { AWSIOTProvider } from "react-aws-iot";
export default () => (
//Whatever goes in here - doesn't matter
...
);
```
2. In whatever component is going to be aware of your connection information, use the `useIOTSettings` hook to make that connection. Like React, its smart enough to make changes only when the underlying data changes, so it stays calm.
```js
const DataFetchingComponent = () => {
const { data, loading, error } = useQuery(MY_QUERY);
const {
region,
accessKeyId,
secretKey,
sessionToken,
host,
iotTopic
} = data.getMyStuff;
useIOTSettings({
region,
accessKeyId,
secretKey,
sessionToken,
host,
iotTopic
});
//...
};
```
3. And where you want to listen for messages, use `useIOT`.
```js
import { useIOT } from "react-aws-iot";
const MessageAwareComponent = () => {
const { message, send, error, status, messageText, messageObj } = useIOT();
};
```
**Note** `messageObj` is a personal favorite because it has translated the raw bytearray to text (via `messageText`) and then decoded it as JSON. Makes a destructured view of the message a one-step process:
```
const { messageObj: { key, value} } = useIOT()
```