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
simplify conditional
  • Loading branch information
AbhineetJain committed Jul 29, 2022
commit 4bcf5e722249d1072379bf99ba3dfecb667e6950
2 changes: 1 addition & 1 deletion site/src/pages/LoginPage/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const LoginPage: React.FC = () => {
const isLoading = authState.hasTag("loading")
const redirectTo = retrieveRedirect(location.search)
const locationState = location.state ? (location.state as LocationState) : null
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to use a ternary because of types? Or can we:

Suggested change
const locationState = location.state ? (location.state as LocationState) : null
const locationState = location.state ?? null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

location.state can be null, but since we are typecasting it, the compiler thinks it is never null, so we are typecasting it only if it is not null.

const isRedirected = locationState !== null ? locationState.isRedirect : false
const isRedirected = locationState ? locationState.isRedirect : false

const onSubmit = async ({ email, password }: { email: string; password: string }) => {
authSend({ type: "SIGN_IN", email, password })
Expand Down