UNPKG

react-native-vision-camera

Version:

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

25 lines (24 loc) 1.26 kB
import { useMemo } from 'react'; import { getCameraDevice } from '../devices/getCameraDevice'; import { useCameraDevices } from './useCameraDevices'; /** * Get the best matching Camera device that best satisfies your requirements using a sorting filter. * * This hook is reactive to device changes. If a new device is plugged in, this hook updates. * * @param position The position of the Camera device relative to the phone. * @param filter The filter you want to use. The Camera device that matches your filter the closest will be returned * @returns The Camera device that matches your filter the closest, or `undefined` if no such Camera Device exists on the given {@linkcode position}. * @example * ```ts * const device = useCameraDevice('back', { * physicalDevices: ['wide-angle'] * }) * ``` */ export function useCameraDevice(position, filter) { const devices = useCameraDevices(); // TODO: Can we use something like useSyncExternalStore or whatever to avoid "wrong" dependencies? // biome-ignore lint/correctness/useExhaustiveDependencies: Filter is a complex object, that'd just re-trigger each render. return useMemo(() => getCameraDevice(devices, position, filter), [devices, position, JSON.stringify(filter)]); }