Last active
February 23, 2017 08:28
-
-
Save TCotton/3ff3382930ed66b1dabe7ea78ce725ac to your computer and use it in GitHub Desktop.
React render if function
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
// 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