React-native : Dynamically update header title in stack navigator

shwetap picture shwetap · Sep 13, 2017 · Viewed 28.2k times · Source

I have made a custom component for header title(stack navigator)which shows user name along with some image. On this page I have to edit the username and on success Update it in header as well

So my question is How to change/update title dynamically?

Answer

Tyler Whitman picture Tyler Whitman · Sep 13, 2017

This can be done using the navigation props.

You can use this.props.navigation.state.params in a component to set a new property. Call:

navigation.setParams({ param: value })

See the documentation on headers for more detail.