Hi Team
I am creating a user registration on react-native, using android on expo go. Now i am tring to call function on press its throwing this exception "undefined is not a function on TouchableOpacity tag atrribute. How can i fix this issue on below code?
import React, { useState } from 'react'
import { Touchable, TouchableOpacity } from 'react-native'
import { KeyboardAvoidingView, StyleSheet, Text, TextInput, View } from 'react-native'
import { auth } from '../firebase'
import { getAuth, createUserWithEmailAndPassword } from 'firebase/auth'
const LoginScreen = () => {
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
// creating authentication with password and login using firebase.
const handleSignUp = () => {
auth.createUserWithEmailAndPassword(email, password).then(userCredential=>{
const user = userCredential.user;
console.log(user.email);
}).catch(error=>alert(error.message))
}
// creating registering users.
return (
setEmail(text)}
style={styles.input}
/>
setPassword(text)}
style={styles.input}
secureTextEntry
/>
{}}
style={styles.button}
>
Login
Register
)
}
export default LoginScreen
const styles = StyleSheet.create({
container:{
flex:1,
justifyContent:'center',
alignItems:'center',
},
inputContainer:{
width:'80%'
},
input:{
backgroundColor:'white',
paddingHorizontal:15,
paddingVertical:10,
borderRadius:10,
marginTop:5
},
buttonContainer:{
width:'60%',
justifyContent:'center',
alignItems:'center',
marginTop:40
},
button:{
backgroundColor:'#0782F9',
width:'100%',
padding:15,
borderRadius:10,
alignItems:'center'
},
buttonOutline:{
backgroundColor:'white',
marginTop:5,
borderColor:'#0782F9',
borderWidth:2
},
buttonOutlineText:{
color:'#0782F9',
fontWeight:'700',
fontSize:16
},
buttonText:{
color:'white',
fontWeight:'700',
fontSize:16
}
})
// firebase js file
// Import the functions you need from the SDKs you need
import {initializeApp} from 'firebase/app';
import {getFirestore} from 'firebase/firestore';
import {getAuth} from 'firebase/auth';
// TODO: Add SDKs for Firebase products that you want to use
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AI***",
authDomain: "eshopmobile-fb508.firebaseapp.com",
projectId: "eshopmobile-fb508",
storageBucket: "eshopmobile-fb508.appspot.com",
messagingSenderId: "734223583165",
appId: "1:734223583165:web:6849ecf86323894686b4d4"
};
// initialize firebase
const app = initializeApp(firebaseConfig);
export const db = getFirestore(app);
export const auth = getAuth();
Guest UserPosted Apr 22, 2023, 11:43 PM
Hi Tuhin
onPress is handle by function called but i am still experience this undefined is not function issue. Swain i have remove Touchable and i using correct package TouchableOpacity
Tuhin PaulPosted Apr 19, 2023, 5:31 PM
The error message "undefined is not a function" suggests that the
onPressattribute you're trying to call is not a function or is undefined. In your code, theonPressattribute of the firstTouchableOpacityis empty, which could be the cause of the error message. Try replacing theonPressattribute with a function that will handle the loginRajkiran SwainPosted Apr 19, 2023, 4:46 PM
The error "undefined is not a function" on the
TouchableOpacitycomponent might be because of a typo or incorrect import of theTouchablecomponent fromreact-nativemodule. Here are the steps you can follow to resolve the issue:TouchableOpacitycomponent correctly from thereact-nativemodule.Remove the
Touchableimport, as it is not used in the code.handleSignUpfunction is defined before it is used in theonPressevent of theTouchableOpacitycomponent.With these changes, your code should work as expected. If the issue persists, you can try clearing the cache of your Expo Go app and restarting the app.