every time I change the state of isActive several times the app crashes and closes automatically When the QR code is read, a modal appears to make updates to a list and the first time it works correctly but from the second time onwards it always gives an error closing my application I'm using it this way
import React from 'react';
import { View, Text } from 'react-native';
import { useAppState } from '@react-native-community/hooks';
import { Camera, useCameraDevice, useCodeScanner } from 'react-native-vision-camera';
import { useIsFocused } from '@react-navigation/core';
import styles from './styles';
export default function ContainerQrcodeScanner({
setDataScanned,
}: {
readonly setDataScanned: (dataqrcode: string) => void;
}) {
const isFocused = useIsFocused();
const appState = useAppState();
const isActive = isFocused && appState === 'active';
const device = useCameraDevice('back');
const codeScanner = useCodeScanner({
codeTypes: ['qr', 'ean-13'],
onCodeScanned: (codes) => {
console.log(`Scanned ${codes.length} codes!`);
console.log(codes[0].value);
setDataScanned(codes[0].value ?? '');
},
});
if (device == null)
return (
<View>
<Text>dispositivo sem camera</Text>
</View>
);
return (
<View style={styles.barcodebox}>
<Camera
style={styles.barcodebox}
device={device}
isActive={isActive}
codeScanner={codeScanner}
torch={'off'}
onError={(e) => console.log(e)}
/>
</View>
);
}
import { useEffect, useState } from 'react';
import { View } from 'react-native';
import { ModalUpdateDevice } from './components/modal';
import styles from './styles';
import ContainerQrcodeScanner from './components/ContainerQrcode';
interface typeshandleBarCodeScanned {
type: string;
data: string;
}
export default function PageScanner() {
const [scannerActive, setScannerActive] = useState<boolean>(true);
const [dataScanned, setDataScanned] = useState<string>('');
useEffect(() => {
setScannerActive(true);
console.log('s');
}, [dataScanned]);
return (
<View style={styles.container}>
{dataScanned ? (
<ModalUpdateDevice
setModalVisible={() => {
setScannerActive(true);
setDataScanned('');
}}
modalVisible={scannerActive}
data={dataScanned}
/>
) : (
<ContainerQrcodeScanner setDataScanned={(data) => setDataScanned(data)} />
)}
</View>
);
}
I tried everything and I don't know what to do