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?