graphql-hooks is a small React GraphQL client built around hooks such as useQuery and useMutation. It wraps a provider and client with optional caching, SSR, and subscriptions support.
Overview
graphql-hooks is a GraphQL client aimed at React applications that prefer a hooks-based API over render-prop components. You create a GraphQLClient, wrap the app with a context provider, and call hooks in child components to fetch and mutate data.
The package emphasizes a concise API and a small bundle size compared with larger clients. Hooks cover queries, manual queries, mutations, and subscriptions, with straightforward loading and error state handling. Optional companion packages add server-side rendering and in-memory cache implementations.
The client talks to a GraphQL HTTP endpoint and can route subscriptions through WebSocket transports such as subscriptions-transport-ws or graphql-ws when configured. Configuration covers headers, middleware, GET for queries, persisted queries, cache control, and pagination patterns.
Documentation contrasts the library with Apollo’s hooks API, noting trade-offs around bundle size versus advanced cache configuration. Migrating from Apollo Client patterns is documented for client, provider, and component equivalents.
Key features
- React hooks API for queries
- useMutation and useSubscription
- Optional memcache plugin
- SSR support via companion package
- Small client bundle
- Manual query hook
- HTTP GET query option
- File upload support
Use cases
- React apps needing a light GraphQL client
- Teams avoiding render-prop GraphQL components
- Server-side rendered React with GraphQL
- GraphQL subscriptions in React
- Migrating from Apollo hook patterns