Skip to content

Instantly share code, notes, and snippets.

@atticoos
Last active June 5, 2017 22:58
Show Gist options
  • Save atticoos/9391dca8da2716093eee95f222a27adc to your computer and use it in GitHub Desktop.
Save atticoos/9391dca8da2716093eee95f222a27adc to your computer and use it in GitHub Desktop.
Optional object dangers
{
If(this.props.person) (
<Text>Hello, {this.props.person.name}</Text> // This still gets unsafely evaluated!
)
}
{
If(this.props.person) (() => (
<Text>Hello, {this.props.person.name}</Text> // Evaluated only when condition passes!
))
}
function If (condition) {
return (componentOrFn) {
if (condition) {
if (typeof condition === 'function') return componentOrFn()
return componentOrFn;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment