Last active
September 23, 2016 22:07
-
-
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
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
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