TypeError - undefined 不是对象(评估 'c.currentObservable.query.refetch')。在反应本机中



我的代码运行良好,但是在快速引用并使用刷新控制进行刷新后,我在 React Native 中遇到了此错误

TypeError - undefined 不是对象(评估 'c.currentObservable.query.refetch'(。

检查错误图片在这里

这是我的代码

const getTopics = useQuery(getAllTopicsSchema);
const [refreshing, setRefreshing] = React.useState<boolean>(false);
<ScrollView
refreshControl={
<RefreshControl
refreshing={refreshing}
onRefresh={() => {
setRefreshing(true);
getTopics.refetch().then((res: any) => { setRefreshing(false)).finally(() => setRefreshing(false));
}} />
}>
{
getTopics.data && getTopics.data.findAllTopic.map((res: Topic) => <View><Text>{JSON.stringify(res)}</Text></View>)
}
</ScrollView>

我不确定这是否有帮助,或者您的问题是否不同,但是当我遇到类似问题时,我发现了这个reddit帖子,并且它为我修复了,所以我在这里添加它供将来的人使用,或者有类似问题的人 反应原生 和 apollo。

您需要检查您的ApolloClient配置,如评论所述:

URI 不能是本地主机,而必须是设备的本地 IP 地址。我花了几个小时才弄清楚这一点。

例如,如果您的配置是这样的

const client = new ApolloClient({
...configRest,
uri: 'http://localhost:4000/graphql'
})

您需要将其更改为

const client = new ApolloClient({
...configRest,
uri: 'http://YOUR_IP_ADDRESS:4000/graphql'
})

相关内容

最新更新