kgnkrkmz
kgnkrkmz

Reputation: 57

javascript one line nested if else error ": expected"

I want to nested if else statement for href in reactjs but I got an syntax error ": expected". Here is my code:

href = {!this.props.activeLanguage ? "https://m.facebook.com/asd1/" : {this.props.activeLanguage.code == "en" ? "https://m.facebook.com/asd1/" : "https://m.facebook.com/asd2/"}}

The reason I check active Language at first it comes undefined.

Upvotes: 0

Views: 204

Answers (1)

Brian Thompson
Brian Thompson

Reputation: 14385

Remove the inner {}, that is object syntax and it is not a valid object. If you need to add grouping use () instead.

href = {!this.props.activeLanguage ? "https://m.facebook.com/asd1/" : this.props.activeLanguage.code == "en" ? "https://m.facebook.com/asd1/" : "https://m.facebook.com/asd2/"}

Upvotes: 0

Related Questions