> ## Documentation Index
> Fetch the complete documentation index at: https://docs.daily.co/llms.txt
> Use this file to discover all available pages before exploring further.

# useDevices

> Returns information about a participant's media devices and their states, along with helper functions that wrap daily-js device-related methods.

`useDevices(): Object`

For more information about the different error states, see the [`camera-error`](https://docs.daily.co/reference/daily-js/events/settings-events#camera-error) event.

## Return value

Returns an object with the following properties:

**cameraError** `Object | null`

Stores the most recent error object that was emitted through the [`camera-error`](https://docs.daily.co/reference/daily-js/events/settings-events#camera-error) event.

**cameras** `Object[]`

An array of [device objects](#device-object-properties) that contains information about each camera.

**camState** `string`

`'idle' | 'pending' | 'not-supported' | 'granted' | 'blocked' | 'in-use' | 'not-found' | 'constraints-invalid' | 'constraints-none-specified' | 'undefined-mediadevices' | 'unknown'`, indicates the general state of camera access.

**currentCam** `Object | undefined`

References the selected device in the `cameras` array.

**currentMic** `Object | undefined`

References the selected device in the `microphones` array.

**currentSpeaker** `Object | undefined`

References the selected device in the `speakers` array.

**hasCamError** `boolean`

`true` in case `camState` is one of `'blocked' | 'in-use' | 'not-found' | 'constraints-invalid' | 'constraints-none-specified' | 'undefined-mediadevices' | 'unknown'`.

**hasMicError** `boolean`

`true` in case `micState` is one of `'blocked' | 'in-use' | 'not-found' | 'constraints-invalid' | 'constraints-none-specified' | 'undefined-mediadevices' | 'unknown'`.

**microphones** `Object[]`

An array of [device objects](#device-object-properties) that contains information about each microphone.

**micState** `string`

`'idle' | 'pending' | 'not-supported' | 'granted' | 'blocked' | 'in-use' | 'not-found' | 'constraints-invalid' | 'constraints-none-specified' | 'undefined-mediadevices' | 'unknown'`, indicates the general state of microphone access.

**refreshDevices** `Function`

Refreshes the list of devices using [`enumerateDevices()`](https://docs.daily.co/reference/daily-js/instance-methods/enumerate-devices).

**setCamera** `Function`

Switches to the camera with the specified `deviceId`. Calls [`setInputDevicesAsync()`](https://docs.daily.co/reference/daily-js/instance-methods/set-input-devices-async).

**setMicrophone** `Function`

Switches to the mic with the specified `deviceId`. Calls [`setInputDevicesAsync()`](https://docs.daily.co/reference/daily-js/instance-methods/set-input-devices-async).

**setSpeaker** `Function`

Switches to the speaker with the specified `deviceId`. Calls [`setOutputDeviceAsync()`](https://docs.daily.co/reference/daily-js/instance-methods/set-output-device-async).

**speakers** `Object[]`

An array of [device objects](#device-object-properties) that contains information about each speaker.

### About `camState` and `micState`

With 0.7.0 `camState` and `micState` have a new default value of `"idle"` (in previous versions of Daily React, this value was `"pending"`).
Both states remain `"idle"` as long as no device access has been requested, which is the case for rooms configured with `start_audio_off: true` and `start_video_off: true`.
Once device access is requested, `camState` and `micState` switch to `"pending"`, as long as device access is pending.
Once the user grants device access they will switch to `"granted"`. In case the user blocked device access they switch to `"blocked"` accordingly.
In case of an [error](https://docs.daily.co/reference/daily-js/events/settings-events.md#camera-error) the most representative error state will be applied.

### Device object properties

**cameras / microphones / speakers item** `Object`

**properties**

**device** `Object`

The same device information returned from [`enumerateDevices()`](https://docs.daily.co/reference/daily-js/instance-methods/enumerate-devices).

**selected** `boolean`

`true` when this specific device is currently being used by [`getUserMedia()`](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia).

**state** `string`

`'granted' | 'in-use'`. `'granted'` means the device is available, `'in-use'` means the device is used by another app.

```json theme={null}
{
  "cameras": [
    {
      "device": <Object>,
      "selected": true,
      "state": "granted",
    },
  ],
  "camState": "granted",
  "currentCam": <Object>,
  "currentMic": <Object>,
  "currentSpeaker": <Object>,
  "hasCamError": false,
  "hasMicError": true,
  "microphones": [
    {
      "device": <Object>,
      "selected": false,
      "state": "in-use",
    },
  ],
  "micState": "in-use",
  "refreshDevices": <Function>,
  "setCamera": <Function>,
  "setMicrophone": <Function>,
  "setSpeaker": <Function>,
  "speakers": [
    {
      "device": <Object>,
      "selected": false,
      "state": "granted",
    },
  ],
}
```

## Example

```jsx theme={null}
import { useDevices } from '@daily-co/daily-react';

export const UseDevicesDemo = () => {
  const devices = useDevices();

  return (
    <ul>
      <li>Cam: {devices.hasCamError ? 'Error' : 'OK'}</li>
      <li>Mic: {devices.hasMicError ? 'Error' : 'OK'}</li>
    </ul>
  );
};
```

## See also

> [card] daily-js methods
>
> * [enumerateDevices()](https://docs.daily.co/reference/daily-js/instance-methods/enumerate-devices.md)
> * [setInputDevicesAsync()](https://docs.daily.co/reference/daily-js/instance-methods/set-input-devices-async.md)
> * [setOutputDeviceAsync()](https://docs.daily.co/reference/daily-js/instance-methods/set-output-device-async.md)

> [card] Events
>
> * [camera-error](https://docs.daily.co/reference/daily-js/events/settings-events.md#camera-error)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.