Skip to content

getParam docs #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 15, 2018
Merged
Changes from all commits
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
19 changes: 19 additions & 0 deletions docs/navigation-prop.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Each `screen` component in your app is provided with the `navigation` prop autom
* `addListener` - subscribe to updates to navigation lifecycle
* `state` - current state/routes
* `setParams` - make changes to route's params
* `getParam` - get a specific param with fallback
* `dispatch` - send an action to router

It's important to highlight the `navigation` prop is _not_ passed in to _all_ components; only `screen` components receive this prop automatically! React Navigation doesn't do anything magic here. For example, if you were to define a `MyBackButton` component and render it as a child of a screen component, you would not be able to access the `navigation` prop on it.
Expand Down Expand Up @@ -150,6 +151,24 @@ class ProfileScreen extends React.Component {
}
```

### `getParam` - Get a specific param value with a fallback

In the past, you may have encountered the frightful scenario of accessing a `param` when `params` is undefined. Instead of accessing the param directly, you can call `getParam` instead.

Before:
```js
const { name } = this.props.navigation.state.params
```

if `params` is `undefined`, this fails

After:
```js
const name = this.props.navigation.getParam('name', 'Peter')
```

if `name` or `param` are undefined, set the fallback to `Peter`.

## Stack Actions

The following actions will work within any StackNavigator:
Expand Down