我们如何在navigationOptions中获得道具或状态?

时间:2022-08-22 21:55:58

I'm getting errors on calling props or states on navigationOptions. How do we get props or states in navigationOptions?

我在navigationOptions上调用道具或状态时遇到错误。我们如何在navigationOptions中获得道具或状态?

Here is PostDetailScreen which render user's name and user's id.

这是PostDetailScreen,它呈现用户的名称和用户的ID。

class PostDetail extends Component {
  static navigationOptions = ({navigation}) => ({
    header: (
        <View>
            <Text>{this.state.username} {this.props.user.id}
            </Text>
        </View>
    )
});

1 个解决方案

#1


1  

Commenting here as I don't have access to comment option. Where have you defined the state.username, also make sure if you've passed the user.id as props from the parent container from where class PostDetail has been called. Please post the error and question in more detail.

在这里评论,因为我无权访问评论选项。你在哪里定义了state.username,还要确保你是否已经从调用了类PostDetail的父容器传递了user.id作为props。请更详细地发布错误和问题。

#1


1  

Commenting here as I don't have access to comment option. Where have you defined the state.username, also make sure if you've passed the user.id as props from the parent container from where class PostDetail has been called. Please post the error and question in more detail.

在这里评论,因为我无权访问评论选项。你在哪里定义了state.username,还要确保你是否已经从调用了类PostDetail的父容器传递了user.id作为props。请更详细地发布错误和问题。