Ternary operator not working in React Challenge

In one of the React challenges an if/else statement was required in shouldComponentUpdate:

    shouldComponentUpdate(nextProps,nextState){
        console.log("Should I update?")

        if(nextProps.value % 2 === 0){
            return true
        } else {
            return false
        }
    }

I thought I’d get clever and replace the if/else with a ternary operator:

    shouldComponentUpdate(nextProps,nextState){
        console.log("Should I update?")
        
        nextProps.value % 2 === 0 ? true : false
        
    }

and got the following error message:

Expected an assignment or function call and instead saw an expression

Could any one point out where I’ve gone wrong?

:slight_smile:

The ternary is just sitting there. You forgot to return it.

You could even drop the ternary and just return the condition.

1 Like

Doh! thanks very much :slight_smile: