react-native-bluetooth-state-manager
Version:
Manage the bluetooth state of your device
20 lines (17 loc) • 436 B
text/typescript
import { useSyncExternalStore } from 'react'
import {
BluetoothStateManager,
type BluetoothState,
} from './BluetoothStateManager'
export const useBluetoothState = (enabled = true): BluetoothState => {
if (!enabled) {
return 'Unknown'
}
return useSyncExternalStore(
(cb) => {
const remove = BluetoothStateManager.addListener(cb)
return remove
},
() => BluetoothStateManager.getStateSync(),
)
}