此代码需要构造函数。我不理解需要使用构造函数来使用“ this”的必要性(Eunãoestou entendendo必需的构造函数para usar或“ this”)
import React, {Component} from 'react';
import {StyleSheet, TouchableOpacity, Text, View} from 'react-native';
class Botao extends Component{
this.styles = StyleSheet.create({}); // requiring a constructor
render(){
return(
<TouchableOpacity>
<View>
<Text>Clique</Text>
</View>
</TouchableOpacity>
);
}
}
Run Code Online (Sandbox Code Playgroud)
我可以不使用它而这样做吗?
class Botao extends Component{
render(){
return(
<TouchableOpacity>
<View>
<Text style={this.styles.texto}>Clique</Text>
</View>
</TouchableOpacity>
);
}
styles = StyleSheet.create({
texto:{
fontSize: 60
}
});
}
Run Code Online (Sandbox Code Playgroud)