Created
July 16, 2015 13:39
-
-
Save frank-weindel/d3c331f76c719c84370b to your computer and use it in GitHub Desktop.
A simple function for simulating an "if statement" within a react render
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
/** | |
* Calls the callback and returns its result if the expression is truthy | |
* | |
* @param {string} expression | |
* @param {Function} callback | |
* @return {variant} Value of callback() if expression is true. Otherwise 'undefined' | |
*/ | |
export function iff(expression, callback) { | |
if (expression) { | |
return callback(); | |
} | |
return void 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment