React Apollo (package `react-apollo`) provided the official React integration for Apollo Client, enabling developers to fetch and manage GraphQL data in React applications using Hooks, Components, and Higher-Order Components (HOCs). Version 3.1.5, released on April 14, 2020, was a stable release within the v3 series. The project has since been officially deprecated, with version 4.0.0 (released July 20, 2020) being its final release. All core React Apollo functionality, including hooks, components, HOCs, SSR, and testing utilities, has been migrated directly into the `@apollo/client` package (v3 and above). Developers are strongly advised to migrate to `@apollo/client` for active maintenance, new features, and bug fixes, as `react-apollo` no longer receives updates or support.
npm install react-apolloVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `react-apollo` with `ApolloClient`, define a GraphQL query using `gql`, and fetch data in a React component using the `useQuery` hook. It renders a list of todos from a public API.
Migrate your application to `@apollo/client`. Refer to the Apollo Client migration guide for detailed instructions. This involves updating imports from `react-apollo` or `@apollo/react-hooks` to `@apollo/client` and its subpaths (e.g., `@apollo/client/react/components`, `@apollo/client/react/hoc`).
Ensure your React version is 16.8 or newer. For components and hooks, consider direct imports from the `@apollo/react-X` packages or, preferably, migrate to `@apollo/client` directly. Update testing utility imports to `@apollo/react-testing`.
Review your `useLazyQuery` implementations when upgrading to 3.1.5. Consult the GitHub issues (#4040) for specific changes and potential workarounds, or migrate to `@apollo/client` which has its own `useLazyQuery` implementation.
If experiencing issues with `MockedProvider` and `@graphql-tools/mock`, consider downgrading `react-apollo` to an earlier 3.x version (e.g., 3.1.3) or migrating your testing setup entirely to `@apollo/client` and its testing utilities (`@apollo/client/testing`).
Ensure `setState` calls in `onCompleted` or `onError` are guarded to prevent re-renders that re-trigger the query/mutation. For example, check if `data` or `error` has changed before updating state, or use a ref to track if a side effect has already been performed.
Ensure your application's root component (or the highest common ancestor of your GraphQL components) is wrapped in `<ApolloProvider client={yourApolloClientInstance}>...</ApolloProvider>`.Always check for `loading` and `error` states before trying to access `data`. For specific issues like #4042, consider upgrading or downgrading `react-apollo` to a working version or, preferably, migrating to `@apollo/client`.
Verify the `uri` in your `HttpLink` configuration is correct and accessible. Check browser console for CORS errors. Ensure your GraphQL server is running and reachable.
Use a ref to track component mounted status or implement cleanup logic (e.g., in `useEffect` for hooks, `componentWillUnmount` for classes) to cancel pending operations or prevent state updates if the component is unmounted.
Review the usage of `useLazyQuery` in your application. Consult GitHub issues (e.g., #4040) for details on the breaking change. Consider pinning to an earlier `react-apollo` 3.x version or migrating to `@apollo/client` which provides its own `useLazyQuery` hook.