Skip to content

Instantly share code, notes, and snippets.

@ralphholzmann
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ralphholzmann/99497d51b43be245fff1 to your computer and use it in GitHub Desktop.
Save ralphholzmann/99497d51b43be245fff1 to your computer and use it in GitHub Desktop.
Ternary vs Non render functions
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>
);
}
});
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