I am trying to set the background of a container based on the state but it keeps showing me an error bg is not defined
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,
}
})
Change this code:
return <View style={[styles.container, backgroundColor: this.state.bg]}/>
for this code:
return <View style={[styles.container, {backgroundColor: this.state.bg}]}/>
Please see my comment below and use like it

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With