This code is requiring a constructor. I'm not understanding the need to have a constructor to use the 'this' (Eu não estou entendendo a necessidade de ter um construtor para usar o '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>
);
}
}
can I do it this way without using it?
class Botao extends Component{
render(){
return(
<TouchableOpacity>
<View>
<Text style={this.styles.texto}>Clique</Text>
</View>
</TouchableOpacity>
);
}
styles = StyleSheet.create({
texto:{
fontSize: 60
}
});
}
styleslike that makes it a class property which is accessed from elsewhere in the class withthis