【发布时间】:2020-12-19 06:03:30
【问题描述】:
执行我的 React Native 应用程序后,我遇到了这个错误:
Could not find "client" in the context or props of Mutation. Wrap the root component in an <ApolloProvider>, or pass an ApolloClient instance via 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>
);
}
}
【问题讨论】:
标签: reactjs react-native apollo-client