Last active
June 5, 2017 22:58
-
-
Save atticoos/9391dca8da2716093eee95f222a27adc to your computer and use it in GitHub Desktop.
Optional object dangers
This file contains hidden or 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
{ | |
If(this.props.person) ( | |
<Text>Hello, {this.props.person.name}</Text> // This still gets unsafely evaluated! | |
) | |
} |
This file contains hidden or 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
{ | |
If(this.props.person) (() => ( | |
<Text>Hello, {this.props.person.name}</Text> // Evaluated only when condition passes! | |
)) | |
} |
This file contains hidden or 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
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