This error I got every time:
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Check the render method of `CameraScreen`.
This error is located at:
in RCTView (created by View)
in View (created by CameraScreen)
in CameraScreen (created by SceneView)
in StaticContainer
in EnsureSingleNavigator (created by SceneView)
in SceneView (created by CardContainer)
in RCTView (created by View)
in View (created by CardContainer)
in RCTView (created by View)
in View (created by CardContainer)
in RCTView (created by View)
in View
in CardSheet (created by Card)
in RCTView (created by View)
in View (created by Animated(View))
in Animated(View) (created by PanGestureHandler)
in PanGestureHandler (created by PanGestureHandler)
in PanGestureHandler (created by Card)
in RCTView (created by View)
in View (created by Animated(View))
in Animated(View) (created by Card)
in RCTView (created by View)
in View (created by Card)
in Card (created by CardContainer)
in CardContainer (created by CardStack)
in RNSScreen (created by Animated(Anonymous))
in Animated(Anonymous) (created by InnerScreen)
in Suspender (created by Freeze)
in Suspense (created by Freeze)
in Freeze (created by DelayedFreeze)
in DelayedFreeze (created by InnerScreen)
in InnerScreen (created by Screen)
in Screen (created by MaybeScreen)
in MaybeScreen (created by CardStack)
in RNSScreenContainer (created by ScreenContainer)
in ScreenContainer (created by MaybeScreenContainer)
in MaybeScreenContainer (created by CardStack)
in RCTView (created by View)
in View (created by Background)
in Background (created by CardStack)
in CardStack (created by HeaderShownContext)
in RNCSafeAreaProvider (created by SafeAreaProvider)
in SafeAreaProvider (created by SafeAreaProviderCompat)
in SafeAreaProviderCompat (created by StackView)
in RNGestureHandlerRootView (created by GestureHandlerRootView)
in GestureHandlerRootView (created by StackView)
in StackView (created by StackNavigator)
in PreventRemoveProvider (created by NavigationContent)
in NavigationContent
in Unknown (created by StackNavigator)
in StackNavigator (created by AppNavigator)
in AppNavigator (created by App)
in EnsureSingleNavigator
in BaseNavigationContainer
in ThemeProvider
in NavigationContainerInner (created by App)
in RCTView (created by View)
in View (created by NativeLinearGradient)
in NativeLinearGradient (created by LinearGradient)
in LinearGradient (created by GradientBackground)
in GradientBackground (created by App)
in App (created by withDevTools(App))
in withDevTools(App)
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in main(RootComponent), js engine: hermes
The code of the component is
import React, { useState, useEffect } from "react";
import { View, Text, StyleSheet, TouchableOpacity } from "react-native";
import { Camera } from "expo-camera";
import { useNavigation } from "@react-navigation/native";
import { CameraType } from "expo-camera/build/legacy/Camera.types";
const CameraScreen = () => {
const [hasPermission, setHasPermission] = useState(null);
const [cameraRef, setCameraRef] = useState(null);
const [type, setType] = useState(CameraType.back);
const navigation = useNavigation();
useEffect(() => {
(async () => {
const { status } = await Camera.requestCameraPermissionsAsync(); // Request camera permissionsCameraPermissionsAsync();
setHasPermission(status === "granted");
})();
}, []);
if (hasPermission === null) {
return <View />;
}
if (hasPermission === false) {
return <Text>No access to camera</Text>;
}
const takePicture = async () => {
if (cameraRef) {
let photo = await cameraRef.takePictureAsync();
console.log(photo.uri);
// You can navigate to another screen with the photo URI or handle it as needed
navigation.navigate("ProductDetailsScreen", { photoUri: photo.uri });
}
};
return (
<View style={styles.container}>
<Camera
style={styles.camera}
type={type}
ref={(ref) => setCameraRef(ref)}
>
<View style={styles.buttonContainer}>
<TouchableOpacity
style={styles.button}
onPress={() => {
setType(
type === CameraType.back ? CameraType.front : CameraType.back
);
}}
>
<Text style={styles.text}> Flip </Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button} onPress={takePicture}>
<Text style={styles.text}> Take Picture </Text>
</TouchableOpacity>
</View>
</Camera>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
},
camera: {
flex: 1,
},
buttonContainer: {
flex: 1,
backgroundColor: "transparent",
flexDirection: "row",
margin: 20,
},
button: {
flex: 0.1,
alignSelf: "flex-end",
alignItems: "center",
},
text: {
fontSize: 18,
color: "white",
},
});
export default CameraScreen;
How can I solve it?
When I open the app it always throws this error. If it’s run I am unable to see anything. I get a blank screen if I try in web so it shows that camera is working by the flash but still nothing on the screen.
1