Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refactor: remove early return from UsersPage
  • Loading branch information
BrunoQuaresma committed Apr 29, 2022
commit b6db33a13a2cda86f8aa127ff69ce90e8cef4266
18 changes: 9 additions & 9 deletions site/src/pages/UsersPage/UsersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ export const UsersPage: React.FC = () => {

if (!users) {
return <FullScreenLoader />
} else {
return (
<UsersPageView
users={users}
openUserCreationDialog={() => {
navigate("/users/create")
}}
/>
)
}
Copy link
Contributor

@presleyp presleyp Apr 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We avoid early return on the frontend (it's a newish decision)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what early return means... but in case there are no users, during the initial load, what should we do instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, your content is fine, I just mean please use else to connect the conditions.

Copy link
Collaborator Author

@BrunoQuaresma BrunoQuaresma Apr 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, ok. I will do that but I'm curious about the reason.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure - the idea is that using else makes it clear that the line of code you're reading is only executed conditionally. Without else, the fact that the line is conditional is only represented by an apparently unrelated if that happens to contain return. So it's easier to misunderstand when maintaining the code.


return (
<UsersPageView
users={users}
openUserCreationDialog={() => {
navigate("/users/create")
}}
/>
)
}