ReactJS – How to change the navigation bar title when viewed

I need to read a value and use it to set the title in the navigation bar.
I am using react-native-router-flux and I am also using redux.
I Navigate to the place where I view my language settings and fire redux actions.
All views receive the new state, in the render() method I can call:

 console.log(this.props.language.language)

This is set through redux.
I want to change the title of the navigation bar, such as:

< pre>Actions.refresh({title: I18n.t(‘main’, {locale: this.props.language.language})})

But this will slow down the application and will not work .
But if it is not in the rendering method, I don’t know where to put it.

you shouldn’t Modify the state in the rendering method-this will cause an infinite loop of changing state to cause re-rendering.

Instead, you should put it in a lifecycle method:

componentDidMount () {
Actions.refresh(...)
}

This trigger will be triggered when the component is installed for the first time.

< /div>

I need to read a value and use it to set the title in the navigation bar.
I am using react-native-router-flux and I am also using redux.
I navigate To see where I set the language and fire redux action.
All views receive the new state, in the render() method I can call:

console .log(this.props.language.language)

This is set through redux.
I want to change the title of the navigation bar, such as:

Actions.refresh({title: I18n.t('main', {locale: this.props.lan guage.language})))

But this will slow down the application and will not work.
But if it is not in the rendering method, I don’t know where to put it.

You should not modify the state in the rendering method-this will cause an infinite loop of changing state resulting in re-rendering.

Instead, you should put it In a life cycle method:

componentDidMount () {
Actions.refresh(...)
}

First time This trigger will be triggered when the component is installed.

Leave a Comment

Your email address will not be published.