Skip to content

Instantly share code, notes, and snippets.

@joecritch joecritch/react.if.js
Last active Aug 29, 2015

What would you like to do?
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
You can’t perform that action at this time.