11import { useEffect , useMemo } from 'react'
2- import { getAllCameraDevices } from '../CameraDevices'
32import { getCameraDevice } from '../devices/getCameraDevice'
43import type {
54 CameraController ,
@@ -26,6 +25,7 @@ import { useCameraSession } from './internal/useCameraSession'
2625import { useCameraSessionIsRunning } from './internal/useCameraSessionIsRunning'
2726import { useListenerSubscription } from './internal/useListenerSubscription'
2827import { useStableCallback } from './internal/useStableCallback'
28+ import { useCameraDevices } from './useCameraDevices'
2929import { useOrientation } from './useOrientation'
3030
3131export interface CameraProps {
@@ -256,11 +256,11 @@ export function useCamera({
256256 } , [ orientation , outputs ] )
257257
258258 // 3. Get the input - either find one via position, or use the user provided one
259+ const devices = useCameraDevices ( )
259260 const input = useMemo ( ( ) => {
260261 if ( typeof device === 'string' ) {
261262 // The user passed a `CameraPosition` (e.g. "back") - try to find a device ourselves
262263 const position = device
263- const devices = getAllCameraDevices ( )
264264 const foundDevice = getCameraDevice ( devices , position )
265265 if ( foundDevice == null ) {
266266 throw new Error ( `This device does not have any "${ position } " Cameras!` )
@@ -270,7 +270,7 @@ export function useCamera({
270270 // The user passed an actual device. return as-is.
271271 return device
272272 }
273- } , [ device ] )
273+ } , [ device , devices ] )
274274
275275 // 4. Configure the session with the input + outputs to create a `CameraController`
276276 const controller = useCameraController ( session , input , outputs , {
0 commit comments