Reputation: 69
I'm getting the above error while i'm trying to run my application.
This is the error that pops up when I hover the mouse over the open bracket of render () in App.js file.
Edit: Added codes
App.js
import React from 'react';
import { StyleSheet, Text, View} from 'react-native';
import {StackNavigator} from 'react-navigation';
import Login from 'apps/components/Login';
const NavigationApp = StackNavigator({
Home: {screen: Login}
,}, {
navigationOptions:{
header: false,
}
}
);
export default class App extends React.Component {
render() {
return (
<NavigationApp />
);
}
}
Login.js
import React from 'react';
import { StyleSheet, Text, View, TextInput, AsyncStorage,
ToacheableOpacity,KeyboardAvoidingView} from 'react-native';
import {StackNavigator} from 'react-navigation';
export default class Login extends React.Component {
constructor (props){
super(props);
this.state={
username:'',
password:'',
}
}
componentDidMount(){
this._loadInitialState().done();
}
_loadInitialState = async () => {
var value= await AsyncStorage.getItem('user');
if (value != null){
this.props.navigation.navigate('profile');
}
}
render() {
return (
<KeyboardAvoidingView behavior='padding' style={styles.wrapper}>
<View style={styles.container}>
<TextInput style={styles.textInput}
placeholder='Usuario' onChangeText={(username)=> this.setState({username})}/>
<TextInput style={styles.textInput}
placeholder='Clave' onChangeText={(password)=> this.setState({password})}/>
<ToacheableOpacity>
style={styles.button} onPress{this.login}
<Text style={styles.buttonText}>Iniciar Seccion</Text>
</ToacheableOpacity>
</View>
</KeyboardAvoidingView>
);
}
login = () =>{
fetch('https://wb382.com/api/mobile/login.php', {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.Stringify({
username: this.state.usersame,
password: this.state.password,
})
})
.then((response)=>response.json())
.then((res)=>{
if (res.success===true){
AsyncStorage.setItem('user',res.user);
this.props.navigation.navigate('profile')
}else{
alert(res.message);
}
})
}
}
const styles = StyleSheet.create({
wrapper:{
flex: 1,
},
container:{
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#000',
paddingLeft: 40,
paddingRight: 40,
},
buttonText:{
fontSize: 26,
color: '#fff',
},
textInput:{
alignSelf: 'stretch',
padding: 16,
marginBotton: 20,
backgroundColor: '#fff',
},
button:{
alignSelf: 'stretch',
backgroundColor: '#1fd100',
padding: 20,
alignItems: 'center',
}
});
I don't know which of these file is producding the error.
To simulate these codes, I'm also hosting my codes at expo.io
https://snack.expo.io/@wilson382/my-first-mobile-app
Upvotes: 0
Views: 369
Reputation: 293
Login component has an error in "ToacheableOpacity". In import statement and render method both are wrong written. It is TouchableOpacity. I've edited your demo code, and changing to the right name fixed the error.
Upvotes: 1