# @developertown/use-bluetooth-notifications

> A react hook to easily use and listen to bluetooth notifications from a specified service and characteristic

Latest version **0.1.0** (published 2020-05-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @developertown/use-bluetooth-notifications
pnpm add @developertown/use-bluetooth-notifications
yarn add @developertown/use-bluetooth-notifications
bun add @developertown/use-bluetooth-notifications
```

## Health

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

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

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2020-05-27 |
| First published | 2020-05-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=12 |
| Dependencies | 0 |
| Unpacked size | 176.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Matt Williams |
| Maintainers | mattwilliamsdev, abillingsley, jasonvasquez |

## Links

- npm: https://www.npmjs.com/package/@developertown/use-bluetooth-notifications
- npm.io page: https://npm.io/package/@developertown/use-bluetooth-notifications

## Recent versions

- 0.1.0 (latest) — 2020-05-27

## README

# use-bluetooth-notifications
A react hook to easily use and listen to bluetooth notifications from a specified service and characteristic

## Usage
There are two options for connecting. You can use the `useBluetoothNotifications` hook directly or use `BluetoothContext` and the `useBluetooth` hook:

### useBluetoothNotifications
```tsx
const [stream, setStream] = useState(); // Track stream state here in onNotification
const { device, status, startStream, stopStream } = useBluetoothNotifications({
  serviceUuid = "health_thermometer",
  characteristicUuid = "temperature_measurement",
  onNotification = (parsedValue: string | number, event: Event): void => {
    setStream(parsedValue);
  },
  onError = (error: Error): void => { ... },
  parser = (value: DataView, offset?: number): number | string => { ... }
});

return (
  <div>
    <button onClick={startStream}>Start</button>
    <button onClick={stopStream}>Stop</button>
  </div>
);
```

### useBluetooth & useBluetoothProvider
```tsx
const MyComponent: React.FC<{}> = () => {
  const { device, server, service, characteristic, status, startStream, stopStream } = useBluetooth();
  return (
    <div>
      <button onClick={startStream}>Start</button>
      <button onClick={stopStream}>Stop</button>
    </div>
  );
};

const App: React.FC<{}> = () => {
  const onNotification = useCallback((parsedValue: string | number, event: Event): void => { ... }, []);
  const onError = useCallback((error: Error): void => { ... }, []);
  const parser = useCallback((value: DataView, offset?: number): number | string => { ... }, []);

  return (
    <BluetoothProvider
      serviceUuid="health_thermometer"
      characteristicUuid="temperature_measurement"
      parser={myParser}
      onNotification={onNotification}
      onError={onError}
    >
      <MyComponent />
    </BluetoothProvider>
  );
};
```

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