Skip to content

Instantly share code, notes, and snippets.

@joecritch
Last active August 29, 2015 13:55
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save joecritch/8699597 to your computer and use it in GitHub Desktop.
Conditional function, compatible with React's JSX precompiler
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