简体   繁体   English

React Native,意外的关键字“This”

[英]React Native, Unexpected Keyword “This”

Why I have an red error marks the dot after This Keyword?为什么我有一个红色错误标记这个关键字后面的点? it says (Unexpected Keyword "This")它说(意外的关键字“这个”)

    render() {
    return (
        <TouchableOpacity onPress={() => this.selectionOnPress({this.props.detail.country})}>
            <Text style={[styles.btnSV, {
                backgroundColor:
                    this.state.selectedButton === {this.props.detail.country} ? "red" : "grey"
            }]}>
                <Text style={styles.btnSV}>{this.props.detail.country}</Text>
            </Text>
        </TouchableOpacity>

    );
}}

Error image错误图片

Try this尝试这个

render() {
    return (
        <TouchableOpacity onPress={() => this.selectionOnPress(this.props.detail.country)}>
            <Text style={[styles.btnSV, {
                backgroundColor:
                    this.state.selectedButton === this.props.detail.country ? "red" : "grey"
            }]}>
                <Text style={styles.btnSV}>{this.props.detail.country}</Text>
            </Text>
        </TouchableOpacity>

    );
}}

I basically removed surrounding curly brackets from 1st and 2nd instances of this.props.detail.country Within JS, these curly brackets are object notation and are missing property names.我基本上从this.props.detail.country的第一个和第二个实例中删除了周围的大括号。在 JS 中,这些大括号是 object 表示法并且缺少属性名称。 3rd instance is JSX template variable.第三个实例是 JSX 模板变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM