I need to use data prop for refresher in scrollview in my component. So I need to call data.refetch
in my onRefresh
for Refresher. But I get data prop is undefined error.
Code:
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);
Why is my data prop is undefined ?
I myself figured it out.
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,
})
}),
);
I mapped the refetch prop to a custom screen prop and called it from RefreshControl.