react-native-vision-camera/package/src/hooks/useCameraDevices.ts
Marc Rousavy 14721d314f
chore: Remove semicolons (#1846)
* chore: Disable `semi` in Prettier

* chore: Format w/o semi

* Remove more `;`

* Lint example

* More ;
2023-09-26 11:39:17 +02:00

24 lines
768 B
TypeScript

import { useEffect, useState } from 'react'
import type { CameraDevice } from '../CameraDevice'
import { CameraDevices } from '../CameraDevices'
/**
* Get all available Camera Devices this phone has.
*
* Camera Devices attached to this phone (`back` or `front`) are always available,
* while `external` devices might be plugged in or out at any point,
* so the result of this function might update over time.
*/
export function useCameraDevices(): CameraDevice[] {
const [devices, setDevices] = useState(() => CameraDevices.getAvailableCameraDevices())
useEffect(() => {
const listener = CameraDevices.addCameraDevicesChangedListener((newDevices) => {
setDevices(newDevices)
})
return () => listener.remove()
}, [])
return devices
}