Skip to content

Instantly share code, notes, and snippets.

@TCotton
Last active February 23, 2017 08:28
Show Gist options
  • Save TCotton/3ff3382930ed66b1dabe7ea78ce725ac to your computer and use it in GitHub Desktop.
Save TCotton/3ff3382930ed66b1dabe7ea78ce725ac to your computer and use it in GitHub Desktop.
React render if function
// Also available as a NPM library: https://github.com/ajwhite/render-if
'use strict';
const isFunction = input => typeof input === 'function';
export default predicate => elemOrThunk =>
predicate ? (isFunction(elemOrThunk) ? elemOrThunk() : elemOrThunk) : null;
import renderIf from '../utils/renderif'
export default class RenderIfExample extends Component {
render() {
var isTrue = true;
return (
<div>
{renderIf(isTrue)(
<h1>I am being rendered</h1>
)}
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment