我正在尝试根据状态设置容器的背景,但它一直向我显示错误 bg 未定义
constructor(props) {
super(props)
this.state = {
bg:'#fff'
}
}
render(){
return(<View style={styles.container} />)
}
const styles = StyleSheet.create({
container:{
flex: 1,
backgroundColor: this.state.bg,
}
})
最佳答案
更改此代码:
return <View style={[styles.container, backgroundColor: this.state.bg]}/>
对于此代码:
return <View style={[styles.container, {backgroundColor: this.state.bg}]}/>
关于react-native - 从样式表响应 native 访问状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54583037/