UNPKG

react-native-vision-camera

Version:

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

31 lines (30 loc) 876 B
import { useEffect, useState } from 'react'; import { VisionCamera } from '../../VisionCamera'; export function useCameraSession({ enableMultiCamSupport, }) { const [session, setSession] = useState(); // session creation useEffect(() => { let isCanceled = false; const load = async () => { const s = await VisionCamera.createCameraSession(enableMultiCamSupport); if (isCanceled) { s.dispose(); return; } setSession(s); }; load(); return () => { isCanceled = true; }; }, [enableMultiCamSupport]); // session teardown useEffect(() => { return () => { // remove all connections session?.stop(); session?.configure([]); }; }, [session]); return session; }