UNPKG

react-native-vision-camera

Version:

VisionCamera is the fastest and most powerful Camera for react-native.

27 lines (26 loc) 863 B
import { useSyncExternalStore } from 'react'; import { addOnCameraDevicesChangedListener, getAllCameraDevices, } from '../CameraDevices'; function subscribe(onStoreChange) { const listener = addOnCameraDevicesChangedListener(() => onStoreChange()); return () => listener.remove(); } function getSnapshot() { return getAllCameraDevices(); } /** * Use a list of all {@linkcode CameraDevice}s on this phone. * * The hook automatically updates with the new devices as * devices get added or removed to the phone - e.g. USB Cameras. * * @see {@linkcode useCameraDevice} * @see {@linkcode getCameraDevice} * @example * ```ts * const devices = useCameraDevices() * const backDevice = devices.find((d) => d.position === 'back') * ``` */ export function useCameraDevices() { return useSyncExternalStore(subscribe, getSnapshot, getSnapshot); }