我正在使用React和Apollo开发一个网站,但抛出错误。我看到这可能与等级制度有关
Could not find "client" in the context or passed in as an option. Wrap the root component in an <ApolloProvider>, or pass an ApolloClient instance in via options.
import React from 'react';
import ReactDOM from 'react-dom';
import { ApolloProvider } from 'react-apollo';
import graphqlClient from './services/graphql';
import App from './App';
import 'bootstrap/dist/css/bootstrap.min.css';
ReactDOM.render(
<ApolloProvider client={graphqlClient}>
<App />,
</ApolloProvider>,
document.getElementById('root'),
);
import React from 'react';
import { BrowserRouter as Router } from 'react-router-dom';
import GlobalStyle from './styles/global';
import Routes from './routes';
const App: React.FC = () => {
return (
<Router>
<Routes />
<GlobalStyle />
</Router>
);
};
export default App;
答案 0 :(得分:1)
确保已在“ ./services/graphql”中正确设置了阿波罗客户端。有关更多信息,我必须看一下该模块。
您使用以前的apollo客户端。如果您开始一个新项目,最好从最新的项目开始。 https://www.apollographql.com/docs/react/