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>;
}