Skip to content

Instantly share code, notes, and snippets.

@chris-kobrzak
Last active September 23, 2016 22:07
Show Gist options
  • Save chris-kobrzak/0796774fe1aa9b50103b1a332a30187b to your computer and use it in GitHub Desktop.
Save chris-kobrzak/0796774fe1aa9b50103b1a332a30187b to your computer and use it in GitHub Desktop.
Less logic in JSX resulting in code that's easier to read and transpiled to a simpler and more compact block of code
render () {
const { visible } = this.props
let visibleContent
if (visible) {
visibleContent = this.getVisibleContent()
}
return (
<div className={ visible ? 'expanded' : 'collapsed' }>
{ visibleContent } // No more logic here and useless "null"
</div>
)
getVisibleContent () {
return ( <div>
// Dozens of lines of JSX code here
</div> )
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment