diff --git a/examples/react/README.md b/examples/react/README.md
index b293178..139b492 100644
--- a/examples/react/README.md
+++ b/examples/react/README.md
@@ -10,25 +10,24 @@ This example uses [React](https://reactjs.org/) and [Apollo GraphQL](https://apo
## Install dependencies
```shell
-$ npm install react react-dom react-apollo apollo-boost graphql graphql-tag
+$ npm install react react-dom @apollo/client graphql
```
## Build the component
```js
-import ApolloClient from 'apollo-boost';
-import React, {Component} from 'react';
+import React, {useState} from 'react';
import ReactDOM from 'react-dom';
-import gql from 'graphql-tag';
-import {Query} from 'react-apollo';
+import {ApolloClient, InMemoryCache, gql, useQuery} from '@apollo/client';
// initialize a GraphQL client
const client = new ApolloClient({
+ cache: new InMemoryCache(),
uri: 'https://countries.trevorblades.com'
});
// write a GraphQL query that asks for names and codes for all countries
-const GET_COUNTRIES = gql`
+const LIST_COUNTRIES = gql`
{
countries {
name
@@ -37,36 +36,24 @@ const GET_COUNTRIES = gql`
}
`;
-// create a component that renders an API data-powered select input
-class CountrySelect extends Component {
- state = {
- country: 'US'
- };
+// create a component that renders a select input for coutries
+function CountrySelect() {
+ const [country, setCountry] = useState('US');
+ const {data, loading, error} = useQuery(LIST_COUNTRIES, {client});
- // set the selected country to the new input value
- onCountryChange = event => {
- this.setState({country: event.target.value});
- };
-
- render() {
- return (
- Loading... {error.message}
{error ? error.message : 'Loading...'}
; } + + return ( + + ); } ReactDOM.render(