In my React Native project, I want to use the QR code reader from react-native-vision-camera version "^3.8.2" (the latest version).
I believe that I have implemented everything correctly according to the documentation, but I am encountering a very strange error.
JSX element class does not support attributes because it does not have a 'props' property.ts(2607)
'Camera' cannot be used as a JSX component.
Its instance type 'Camera' is not a valid JSX element.
Type 'Camera' is missing the following properties from type 'ElementClass': context, setState, forceUpdate, props, and 2 more.
My implementation:
import { useCameraPermission, useCameraDevice, useCodeScanner, CameraProps, Camera } from "react-native-vision-camera";
import { View } from "react-native";
const QrScanner = () => {
const device = useCameraDevice('back')
const { hasPermission, requestPermission } = useCameraPermission();
const codeScanner = useCodeScanner({
codeTypes: ['qr', 'ean-13'],
onCodeScanned: (codes) => {
console.log(`Scanned ${codes.length} codes!`)
}
});
if (!device) return <View />;
return (
<View>
<Camera device={device} {...codeScanner} />
</View>
);
};
export default QrScanner;
Any ideas?
i tried
<Camera codeScanner={codeScanner} />
The same error here.
When
Componentcannot be used as a JSX component, it is a Typescript error that can come from a few different areas.v3.5.1.babelmay also not be configured correctly. Look through the packages Example App and make sure your configs/packages all match up.@types/package versions match your corresponding packages, such as@types/react: x.x.xmatches yourreact: x.x.xor
npm install --save-dev @types/react @types/react-dom @types/react-nativeor use yarn instead of npm to update.Best of luck!