I want to put a part of data (username) from fetched props on navigation header. Please see my navigationOptions
.
static navigationOptions = ({navigation, screenProps}) => ({
...
title: !_.isNil(screenProps.outfitDetail) ?
`${screenProps.outfitDetail.user.username}'s Post`: ''
});
My problem is that title
always return a blank string because screenProps.outfitDetail
is always null. What am I doing wrong here? Why is it returning null all the time?
I fetched outfitDetail props using Redux on componentWillMount()
componentWillMount() {
const { id } = this.props.navigation.state.params;
const { token, hType} = this.props;
this.props.fetchOutfitDetail(token, hType, id);
}
I could get the outfitDetail props from render() function
.
render () {
const detail = this.props.outfitDetail;
if(detail) {
return (
<ScrollView style={styles.root}>
...
I call my component by its id
this.props.navigation.navigate('OutfitDetail', {id})
Doing same thing on User Profile
console.log(this.props.currentUser.username); <- prints username
this.props.navigation.navigate('Profile', {username:this.props.currentUser.username});
But in Profile screen, it can't get screenProps.username
either.