Skip to content

Instantly share code, notes, and snippets.

@yann-yinn
Last active May 17, 2018 07:50
Show Gist options
  • Save yann-yinn/c73a44e96fb73872e89b2f9e33e8b5f6 to your computer and use it in GitHub Desktop.
Save yann-yinn/c73a44e96fb73872e89b2f9e33e8b5f6 to your computer and use it in GitHub Desktop.
if, else, return & natural language
/**
* 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