Last active
August 29, 2015 13:55
-
-
Save joecritch/8699597 to your computer and use it in GitHub Desktop.
Conditional function, compatible with React's JSX precompiler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
React.if = function(cond, trueCallback, falseCallback) { | |
if(cond && typeof trueCallback === 'function') { | |
return trueCallback(); | |
} | |
else if(!cond && typeof falseCallback === 'function') { | |
return falseCallback(); | |
} | |
}; | |
// Example usage | |
var thisIsTrue = true; | |
{React.if(thisIsTrue, function() { | |
return (<p>True!</p>); | |
}, function() { | |
return (<p>False!</p>); | |
})} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment