Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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