0

I have a dumb styling compile error.. Can anyone tell me the correct syntax... Here is my code...

<TouchableOpacity style={{marginRight:40}} onPress={() => this.handleBlueSelection}>
    <View style={this.state.blue_selected ? {styles.team_selected} : {null}}>
        <Image style={{height:30, width:30}} source={require('../../assets/images/blue.png')} />
    </View>
</TouchableOpacity>

Here is the error:

TransformError SyntaxError: C:\edit_profile.js: Unexpected token, expected "," (294:54)

I know is a dumb question but cannot find the correct syntax..

Thanks

5
  • So have a look @ line 294, char 54 then (C:\edit_profile.js) Commented Oct 31, 2020 at 16:21
  • Which line is line 294? Commented Oct 31, 2020 at 16:22
  • @T.J.Crowder don't know, but the error message says so.. Commented Oct 31, 2020 at 16:24
  • @Reto - That was a question for the OP, not for you. :-) Commented Oct 31, 2020 at 16:33
  • that line : <View style={this.state.blue_selected ? {styles.team_selected} : {null}} > Commented Oct 31, 2020 at 17:04

1 Answer 1

3
<View style={this.state.blue_selected ? {styles.team_selected} : {null}} >

styles.team_selected and null don't need braces around them. The reason the other style requires them is because you need to pass an object of styles (the first pair is to denote js, the second pair constructs the style object).

Sign up to request clarification or add additional context in comments.

2 Comments

this compiles but do not work. Either blue_selected is true or false always is null... styles.team_selected is never active
Sounds like a completely different question altogether. But maybe take a look at this part here onPress={()=> this.handleBlueSelection}. You're not actually calling handleBlueSelection on press, you're just returning a reference to it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.