reactjs - TypeError - undefined 不是一个对象(评估 'c.currentObservable.query.refetch' )。在 native react 中

标签 reactjs react-native react-hooks react-apollo

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

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

Check error Image here

这是我的代码

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>

最佳答案

我不确定这是否有帮助,或者您的问题是否有所不同,但我找到了 this reddit post虽然我遇到了类似的问题并且它已为我修复,所以我将它添加到这里以供将来的人使用或在 React Native 和 apollo 中遇到类似问题。

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

the uri can't be localhost and instead has to be your device's local ip address. Took me hours to figure this out.

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

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

您需要将其更改为

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

关于reactjs - TypeError - undefined 不是一个对象(评估 'c.currentObservable.query.refetch' )。在 native react 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62442422/

相关文章:

javascript - 从 URL 加载图像时正在加载旋转器

javascript - 无法读取未定义的 react 导航的属性 'routeName'

reactjs - React Native 项目中哪些文件夹应该被 git 忽略?

javascript - react native : Write value to variable outside of a inner function

javascript - 使用 react 路由器显示完整的新页面

javascript - 是否有条件地呈现 React 组件而不是原始标记以节省性能?

reactjs - 想知道为什么组件更新时会执行 componentWillUnmount

react-native - useRef 钩子(Hook)不适用于 lottie-react-native

javascript - react useContext() 性能,自定义钩子(Hook)内的 useContext

javascript - 异步 API 调用的无效 Hook 调用