React Native - React Apollo - 数据属性未定义

React Native - React Apollo - data prop undefined

我需要在组件的滚动视图中使用数据属性来刷新。所以我需要在 onRefresh 中调用 data.refetch 进行复习。但是我得到 data prop is undefined 错误。

代码:

class abc extends Component {
    render() {
      return (
        <View>
          <ScrollView
            onRefresh={this.props.data.refetch} // undefined error
            refreshing={this.props.data.loading} // undefined erro    
          >
          .....
           </ScrollView>
        </View>
      );
    }
}

export default compose(
 ....,
 graphql(
   MyQuery,{
      .....
   }
 )
)(abc);

为什么我的数据属性是未定义的?

我自己想出来了

class abc extends Component {
    static propTypes = {
      ....
      refetchData: PropTypes.func.isRequired,
      ....
    };

    render() {
      return (
        <ScrollView>
          <RefreshControl
            onRefresh={this.props.refetchData}
            refreshing={this.props.refreshing}
          />
        </ScrollView>
      );
    }
}

export default compose(
  graphql(MyQuery, {
    props: props => ({
      refetchData: props.data.refetch,
      refreshing: props.data.networkStatus === 4,
    })
  }),
);

我将 refetch 道具映射到自定义屏幕道具并从 RefreshControl 调用它。