Skip to content

useConnectDevice

useConnectDevice(): ConnectDeviceResult

Defined in: console-sdk/src/react/hooks/useConnectDevice.ts:145

Connect devices with the paired-verb contract (SDK_PLAN.md §3.6.2, §3.8.3). connect(target) NEVER rejects — it resolves the Device at ready or null, routing the typed ConnectError into errors keyed by device — so onPress={() => connect(item)} can never float an unhandled rejection. connectAsync(target) is the rejecting twin for imperative flows (NFC/QR, sequencing).

Concurrent connects to different devices are legal and each is tracked independently: pendingIds lists the in-flight devices whose id is known, errors records one failure per device (concurrent failures never overwrite each other), and reset(id?) clears one device’s failure or all. The canonical per-row busy signal remains device.connection.status === 'connecting'; pendingIds exists for screens without the row’s device at hand. Safe from the first render; throws OutsideProviderError when no <ConsoleProvider> is above the caller.

ConnectDeviceResult

the ConnectDeviceResult verb pair + reactive per-device { isPending, pendingIds, errors } + reset.

const { connect, errors, reset } = useConnectDevice();
<DeviceRow onPress={() => connect(item)} />; // never rejects