DEV Community

Discussion on: DevTips: Use early returns to avoid nested conditions

Collapse
 
thomasjunkos profile image
Thomas Junkツ • Edited

And then there is:

render() {
  const personToLookFor = 'Thierry'
  const [result, loading] = doesPersonExist(personToLookFor)

  if (loading) return 'Loading...'
  return result ? `${personToLookFor} already exists.`
                : `${personToLookFor} doesn't exist.`;
}

Besides: Your function doesPersonExist() should take personToLookFor as a parameter - unless it's magical aware of what you want. ;)

Collapse
 
yvonnickfrin profile image
🦁 Yvonnick FRIN • Edited

Thank you for reporting it Thomas, I fixed it 👍