Skip to content

Commit

Permalink
RealmScreen: Assume navigation.state.params will exist.
Browse files Browse the repository at this point in the history
There is no legitimate case in which we navigate to `RealmScreen`
without passing `params`, so it's not `RealmScreen`'s job to decide
what happens if `params` is missing.

Thankfully, we've centralized the navigate-to-`RealmScreen` logic in
`navigateToRealmScreen` in navActions.js, and, there, it's clear
that `params` is being passed.

In React Navigation v5, which is a dramatic departure from the
current API, we may get more robust type-checking, so that it's
feasible to catch any instances where we inadvertently don't pass
`params` [1].

[1] https://reactnavigation.org/docs/typescript/
  • Loading branch information
chrisbobbe committed Oct 1, 2020
1 parent 9e32141 commit 6f6a3ee
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/start/RealmScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type SelectorProps = {|

type Props = $ReadOnly<{|
navigation: NavigationScreenProp<{
params: ?{|
params: {|
realm: URL | void,
initial?: boolean,
|},
Expand Down Expand Up @@ -103,7 +103,7 @@ class RealmScreen extends PureComponent<Props, State> {
return (
<Screen
title="Welcome"
canGoBack={!this.props.navigation.state.params?.initial}
canGoBack={!this.props.navigation.state.params.initial}
padding
centerContent
keyboardShouldPersistTaps="always"
Expand Down Expand Up @@ -139,5 +139,5 @@ class RealmScreen extends PureComponent<Props, State> {
}

export default connect<SelectorProps, _, _>((state, props) => ({
initialRealm: props.navigation.state.params?.realm?.toString() ?? '',
initialRealm: props.navigation.state.params.realm?.toString() ?? '',
}))(RealmScreen);

0 comments on commit 6f6a3ee

Please sign in to comment.