Skip to content

Commit

Permalink
Throw error in development mode when title is not a string
Browse files Browse the repository at this point in the history
  • Loading branch information
brentvatne committed Jun 28, 2018
1 parent cad3d70 commit bc01a4c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
- Throw error in development mode when header navigation option is set to a string - a common mistake that would otherwise result in a cryptic error message.
- Update react-navigation-drawer to 0.4.3 to fix `initialRouteParams` option
- Throw error in development mode when title is not a string.

## [2.5.4] - [2018-06-27](https://github.com/react-navigation/react-navigation/releases/tag/2.5.4)
### Fixed
Expand Down
9 changes: 9 additions & 0 deletions src/views/Header/Header.js
Expand Up @@ -55,6 +55,15 @@ class Header extends React.PureComponent {
if (typeof options.headerTitle === 'string') {
return options.headerTitle;
}

if (options.title && typeof options.title !== 'string' && __DEV__) {
throw new Error(
`Invalid title for route "${
scene.route.routeName
}" - title must be string or null, instead it was of type ${typeof options.title}`
);
}

return options.title;
}

Expand Down

3 comments on commit bc01a4c

@nitaking
Copy link

Choose a reason for hiding this comment

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

@brentvatne
Why did you commit this?
My header used <Image /> and I was surprised to get an error.

Is it useless unless it is a string?

@brentvatne
Copy link
Member Author

@brentvatne brentvatne commented on bc01a4c Jul 4, 2018

Choose a reason for hiding this comment

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

you should use headerTitle instead of title in that case. title is a string can it can cause problems if that is not the case, thus the warning

@nitaking
Copy link

Choose a reason for hiding this comment

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

I see.It worked.
It is to use properly according to the purpose! Thank you!

Please sign in to comment.