Reactjs 找不到“;“客户”;在突变的背景或道具中

Reactjs 找不到“;“客户”;在突变的背景或道具中,reactjs,react-native,apollo-client,Reactjs,React Native,Apollo Client,执行React本机应用程序后,我遇到以下错误: 在变异的上下文或道具中找不到“客户端”。将根组件包装到中,或通过props传递客户端实例。 这是我的阿波罗客户 import { Platform } from "react-native"; import { ApolloClient, InMemoryCache } from "@apollo/client"; // To access our host machine and not the devi

执行React本机应用程序后,我遇到以下错误:
在变异的上下文或道具中找不到“客户端”。将根组件包装到中,或通过props传递客户端实例。

这是我的阿波罗客户

import { Platform } from "react-native";
import { ApolloClient, InMemoryCache } from "@apollo/client";

// To access our host machine and not the device itself we use a special ip on android
// If we are using IOS access localhost:4000 else use 10.0.0.2:4000
const host =
  Platform.OS === "ios" ? "http://localhost:4000" : "http://10.0.2.2:4000";

export const client = new ApolloClient({
  uri: host,
  cache: new InMemoryCache(),
});
下面是index.tsx,它包装了我的根组件:

import { ApolloProvider } from '@apollo/client';
import { client } from "./apollo";
import { Routes } from "./routes/index";

export default class App extends React.PureComponent {
  render() {
    return (
      <ApolloProvider client={client}>
        <Routes />
      </ApolloProvider>
    );
  }
}
从'@apollo/client'导入{ApolloProvider};
从“/apollo”导入{client};
从“/Routes/index”导入{Routes};
导出默认类App扩展React.PureComponent{
render(){
返回(
);
}
}

在V3.0之前
react apollo
apollo client
(和其他子包)在不同的包中(产生了许多与包版本相关的问题/错误。-或-)

最好的办法是迁移到阿波罗客户端3.0

react apollo软件包已被弃用,其功能 由上述每个软件包提供,现在可以从 @阿波罗/客户

Apollo V3.0Great“入门”/tuturial示例+沙盒:

客户 在您的情况下,
客户端
似乎未定义。运行和测试:

console.log(client); /* return object -or- not? */
尝试在一个文件中运行此代码(如果此代码工作正常,请分离所需的文件并使用
module.exports

从“React”导入React;
从“react dom”导入{render};
进口{
阿波罗客户,
在记忆中,
阿波罗供应商,
使用查询,
gql
}来自“@apollo/client”;
export const client=新客户端({
uri:“https://48p1r2roz4.sse.codesandbox.io",
缓存:新的InMemoryCache()
});
导出默认类App扩展React.PureComponent{
render(){
返回(

我的第一个阿波罗应用程序我已经更新了代码以使用
@Apollo/client
,尽管我仍然收到相同的错误。是否与
路由
相关?不幸的是,我无法。