Last active
August 28, 2019 01:43
-
-
Save johnborges/dfcdb1914fc269751a490593664c521c to your computer and use it in GitHub Desktop.
Logic-Less JSX. Keep the JSX of your components clean by putting data logic in variables.
This file contains 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
const Animal = ({ id, name, legCount, isFriendly }) => { | |
const url = `url/animal/${id}` | |
const legCountStr = toString(legCount) || '?' | |
const friendliness = { true: 'Friendly', false: 'Unfriendly' }[isFriendly] | |
const hasNotEnoughData = legCount === undefined && isFriendly === undefined | |
return ( | |
<li> | |
<a href={url}>{name}</a> - {legCountStr} legs | |
{friendliness && ` - ${friendliness}`} | |
{hasNotEnoughData && ' - Not enough data!'} | |
</li> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment