小编wes*_*sif的帖子

是否需要JavaScript / React的构造方法?

此代码需要构造函数。我不理解需要使用构造函数来使用“ 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)

javascript reactjs react-native

0
推荐指数
1
解决办法
35
查看次数

标签 统计

javascript ×1

react-native ×1

reactjs ×1