【发布时间】:2018-07-01 20:57:38
【问题描述】:
我定义了以下组件:
import React, { Component } from 'react';
import { StyleSheet, TouchableOpacity, View, Text } from 'react-native';
export default class Button extends Component {
render() {
return (
<TouchableOpacity onPress={() => this.props.onPress}>
<View style={styles.container}>
<Text
style={{
color: this.props.foregroundColor,
}}
>
{this.props.title}
</Text>
</View>
</TouchableOpacity>
)
}
}
const styles = StyleSheet.create({
container: {
paddingTop: 15,
paddingBottom: 15,
paddingRight: 20,
paddingLeft: 20
},
});
我想将一个 prop backgroundColor 传递给这个组件。但是如何扩展当前的styles.container 以动态设置backgroundColor?我试过了
<View style={
...styles.container,
backgroundColor: this.props.backgroundColor
}>...
但是当我这样做时,我会得到一个SyntaxError...
【问题讨论】:
标签: javascript reactjs react-native ecmascript-6