React tip: To keep JSX simple, return early


React tip: To keep JSX simple, return early.

Check for loading, 404s, or other errors first.

#react

In this example, returning early avoids the need for nested ternaries, which are harder to read.

And returning early means I don't need to extract the logic to a separate function merely so that I can implement an if/else (if/else isn't supported inside a return)
Shameless plug: The example above is from my new "Managing React State" course: https://app.pluralsight.com/library/courses/react-state-managing/table-of-contents

View original on X