Last active
August 29, 2015 14:22
-
-
Save ralphholzmann/99497d51b43be245fff1 to your computer and use it in GitHub Desktop.
Ternary vs Non render functions
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
React.createClass({ | |
displayName: 'SearchSuggestions', | |
propTypes: { | |
suggestions: React.PropTypes.array.required | |
} | |
renderNoSuggestions () { | |
return ( | |
<h3>No suggestsions found.</h3> | |
); | |
}, | |
renderSuggestions () { | |
return this.props.suggestions.map((suggestion) => { | |
return ( | |
<div>{suggestion.name}</div> | |
); | |
}) | |
}, | |
render () { | |
let content; | |
if (this.props.suggestions.length) { | |
content = this.renderSuggestions(); | |
} else { | |
content = this.renderNoSuggestions(); | |
} | |
return ( | |
<div className="container"> | |
<h1>Search Suggestions</h1> | |
{content} | |
</div> | |
); | |
} | |
}); |
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
React.createClass({ | |
displayName: 'SearchSuggestions', | |
propTypes: { | |
suggestions: React.PropTypes.array.required | |
} | |
renderNoSuggestions () { | |
return ( | |
<h3>No suggestsions found.</h3> | |
); | |
}, | |
renderSuggestions () { | |
return this.props.suggestions.map((suggestion) => { | |
return ( | |
<div>{suggestion.name}</div> | |
); | |
}) | |
}, | |
render () { | |
return ( | |
<div className="container"> | |
<h1>Search Suggestions</h1> | |
{this.props.suggestions.length ? this.renderSuggestions() : this.renderNoSuggestions()} | |
</div> | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment