Skip to content

Instantly share code, notes, and snippets.

@frank-weindel
Created July 16, 2015 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frank-weindel/d3c331f76c719c84370b to your computer and use it in GitHub Desktop.
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
/**
* 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