react-native-vision-camera
Version:
VisionCamera is the fastest and most powerful Camera for react-native.
28 lines (27 loc) • 796 B
JavaScript
import { useEffect, useMemo } from 'react';
import { VisionCamera } from '../VisionCamera';
/**
* Use a {@linkcode CameraObjectOutput}.
*
* @example
* ```ts
* const objectOutput = useObjectOutput({
* types: ['qr'],
* onObjectsScanned(objects) {
* console.log(`Scanned ${objects.length} objects!`)
* }
* })
* ```
*/
export function useObjectOutput({ types, onObjectsScanned, }) {
// 1. Create object output
const objectOutput = useMemo(() => VisionCamera.createObjectOutput({
enabledObjectTypes: types,
}), [types]);
// 2. Update onObjectsScanned() callback if it changed
useEffect(() => {
objectOutput.setOnObjectsScannedCallback(onObjectsScanned);
}, [objectOutput, onObjectsScanned]);
// 3. Return :)
return objectOutput;
}