Reputation: 930
Need to pass state to navigation but this.state.
not working, here is the code
this.setState({
demo:"some title"
});
.....
static navigationOptions = {
headerRight:(<View>
<Text>{this.state.demo}</Text>
</View>),
};
Upvotes: 2
Views: 863
Reputation: 848
try to set param something like this :
componentWillMount() {
const {setParams} = this.props.navigation;
setParams({demotxt:this.state.demo});
}
..
static navigationOptions = ({ navigation }) => {
const {state} = navigation;
return {
headerRight: (<View>
<Text>{state.params.demotxt}</Text>
</View>)
}
};
Upvotes: 2
Reputation: 481
I have modified this line, you should call it like this.
<Text>{this.state.demo}</Text>
</View>),
Also, you should first declare your state in constant, and then pass the Const, whenever setState is called. the render function will be invoked. Something like this.
static navigationOptions = {
const title = this.state.demo;
headerRight:(<View>
<Text>{this.state.demo}</Text>
</View>),
};
Upvotes: 0