The Guild LogoThe Guild Monogram

Search docs

Search icon

Products by The Guild

Products

Hive logoHive blurred logo

Hive

Schema Registry for your GraphQL Workflows

Docs

Get Started

Using Subscriptions with React#

useSubscription#

Hook designed to be used for GraphQL Subscriptions.

For more configuration of Subscriptions check here.

Features:#

  • Subscribe on-demand
  • Automatic unsubscribe on component unmount
  • Automatic updates on cache changes

Example#

import { useSubscription } from '../gqty'; export function Example() { const { newNotification } = useSubscription(); if (newNotification) { return ( <p> New Notification: <b>{newNotification}</b> </p> ); } return <p>Waiting for new notifications...</p>; }