When I pulled the user.uid from the AuthContext using useContext, I encountered an error. Essentially, I want to allow the logged-in user to delete a shared post only if the userID matches the logged-in user's ID. However, when comparing user.uid == post.userId, I am getting this error: TypeError: null is not an object (evaluating 'user.uid'). How can I resolve this issue?
import { AuthContext } from "../../Pages/AuthProvider/AuthProvider";
const PostCard = ({post}) => {
const {user} = useContext(AuthContext);
const userID=user.uid;
return(
<View style={styles.container}>
<View style={styles.header}>
<View style={styles.inner1_container}>
<Image
style={styles.profile_image}
source={ProfileImg}
/>
<Text style={styles.username_text}>username</Text>
</View>
<View style={styles.inner2_container}>
<Text style={styles.like_text}>Likes: {post.likes}</Text>
<View style={styles.like_button}>
<TouchableWithoutFeedback
onPress={liked}
>
<Image
style={styles.like_button_image}
source={isLiked ? likedPaw : unLikedPaw}
/>
</TouchableWithoutFeedback>
</View>
</View>
</View>
<View style={styles.describe_container}>
<Text numberOfLines={8} style={styles.describe_text}>{post.description}</Text>
{
post.contact != "" && (<>
<Text numberOfLines={2} style={styles.contact_text}>Contact: {iltetisimtext}{post.contact} </Text>
</>)
}
<Text style={styles.time_text}>Share Time</Text>
{
user.uid == post.userId && (<>
<Text style={styles.time_text}>Delete</Text>
</>)
}
</View>
</View>
)
}