Last active
May 17, 2018 07:50
-
-
Save yann-yinn/c73a44e96fb73872e89b2f9e33e8b5f6 to your computer and use it in GitHub Desktop.
if, else, return & natural language
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
/** | |
* Can be read like a natural language from top to bottom : | |
* "the function withTodosNull returns a function. If todos is null, | |
* this function return null, else, it return Component | |
*/ | |
function withTodosNull(Component) { | |
return function (props) { | |
if (!props.todos) { | |
return null | |
} | |
else { | |
return <Component { ...props } /> | |
} | |
} | |
} | |
/** | |
* shorter but far from natural language | |
*/ | |
const withTodosNull = (Component) => (props) => | |
!props.todos | |
? null | |
: <Component { ...props } /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment