I am using react-native-camera for the first time and I am using functional component for that. I want to open the camera on button click but using the ref is not working. Here is my code :
const camContainer = () => {
const cameraRef = useRef(null);
useEffect(() => {
console.log(cameraRef);
}, [cameraRef]);
const openCamera = () => {
const options = {quality: 0.5, base64: true};
// cameraRef.current.takePictureAsync(options);
console.log(cameraRef);
};
return (
<TouchableOpacity onPress={() => openCamera()}>
<Text>Open Camera</Text>
{!cameraRef && (
<View>
<RNCamera ref={cameraRef} style={{flex: 1, alignItems: 'center'}} />
</View>
)}
</TouchableOpacity>
);
};
I logged cameraRef
using useEffect
but the cameraRef.current
was still null, I cannot understand how do I open the camera then ?