小编GW *_*W D的帖子

在react-native中使用“apolloClient”通过“useQuery”加载数据时,“loading”保持为true

我正在尝试使用useQueryReact Native 中的 Apollo Client 获取数据,但loading挂起在 true 状态并且无法获取data.

\n

下面是实际的代码。

\n

App.js

\n
import React from \'react\';\n\nimport { SafeAreaView, Text, View } from \'react-native\';\n\nimport { ApolloClient, ApolloProvider, InMemoryCache, gql, useQuery } from \'@apollo/client\';\n\nconst EXCHANGE_RATES = gql`\n    query GetExchangeRates {\n        rates(currency: "USD") {\n            currency\n            rate\n        }\n    }\n`;\n\nconst TestScreen = () => {\n    const { loading, error, data } = useQuery(EXCHANGE_RATES);\n\n    console.log(loading, error, data); // Stop at "true undefined undefined" \n\n    if (loading) return <Text>Loading...</Text>;\n    if …
Run Code Online (Sandbox Code Playgroud)

react-native apollo-client

5
推荐指数
1
解决办法
7763
查看次数

标签 统计

apollo-client ×1

react-native ×1