17 lines
698 B
TypeScript
Raw Normal View History

2021-02-20 23:20:28 +01:00
import { useMemo } from 'react';
2021-02-23 08:50:51 +01:00
import type { CameraDevice, CameraDeviceFormat } from '../CameraDevice';
import { sortFormats } from '../utils/FormatFilter';
2021-02-20 23:20:28 +01:00
/**
* Returns the best format for the given camera device.
*
* This function tries to choose a format with the highest possible photo-capture resolution and best matching aspect ratio.
*
* @param {CameraDevice} device The Camera Device
2021-02-20 23:20:28 +01:00
*
* @returns The best matching format for the given camera device, or `undefined` if the camera device is `undefined`.
*/
export function useCameraFormat(device?: CameraDevice): CameraDeviceFormat | undefined {
return useMemo(() => device?.formats.sort(sortFormats)[0], [device?.formats]);
2021-02-20 23:20:28 +01:00
}