fn
useBluetooth
v0.0.15testeddemoReactive Web Bluetooth API. Prompts for a device and tracks its GATT server connection.
Examples
ts
const { isSupported, isConnected, device, requestDevice, server, error } = useBluetooth({
acceptAllDevices: true,
});
requestDevice();ts
// Filter by advertised service and request access to the battery service
const { device, requestDevice, server } = useBluetooth({
filters: [{ services: ['heart_rate'] }],
optionalServices: ['battery_service'],
});Demo
Loading demo…
Signature
ts
export function useBluetooth(options: UseBluetoothOptions ={ ... }Parameters
| Parameter | Type | Description |
|---|---|---|
options? | UseBluetoothOptions | Options |
Returns
UseBluetoothReturn`isSupported`, `isConnected`, `device`, `requestDevice`, `connect`, `disconnect`, `server`, and `error`