Next.js example with graphql-react
graphql-react is a GraphQL client for React using modern context and hooks APIs that is lightweight (< 3 KB size limited) but powerful; the first Relay and Apollo alternative with server side rendering.
Execute create-next-app with npm, Yarn, or pnpm to bootstrap the example:
npx create-next-app --example with-graphql-react with-graphql-react-appyarn create next-app --example with-graphql-react with-graphql-react-apppnpm create next-app --example with-graphql-react with-graphql-react-appDeploy it to the cloud with Vercel (Documentation).
- In
pages/_app.jsa customAppcomponent is decorated with thewithGraphQLApphigher-order component fromnext-graphql-react, generating agraphqlprop that populates theGraphQLProvidercomponent fromgraphql-react. - In
pages/index.jstheuseGraphQLReact Hook fromgraphql-reactis used to query the GraphQL Pokémon API and show a picture of Pikachu.