How to use the urql.useSubscription function in urql

To help you get started, we’ve selected a few urql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github FormidableLabs / urql / examples / 2-using-subscriptions / src / app / Messages.tsx View on Github external
export const Messages: FC = () => {
  const handleSubscription = (
    messages: MessageEntry[] = [],
    response: MessageResponse
  ) => [response.newMessages, ...messages];

  const [res] = useSubscription(
    { query: NewMessageSubQuery },
    handleSubscription
  );

  if (res.error !== undefined) {
    return {res.error.message};
  }

  if (res.data === undefined) {
    return <p>No new messages</p>;
  }

  return (
    <ul>
      {res.data.map(notif =&gt; (
        </ul>
github FormidableLabs / urql / examples / 2-using-subscriptions / src / app / Home.tsx View on Github external
export const Home: FC = () =&gt; {
  const handleSubscription = (
    notifications: NotificationResponse[],
    notification: NotificationResponse
  ) =&gt; [...notifications, notification];

  const [subscription] = useSubscription&lt;
    NotificationResponse,
    NotificationResponse[]
  &gt;({ query: NotificationSubQuery }, handleSubscription);

  if (subscription.error) {
    return {subscription.error.message};
  }

  return subscription.data.map(notif =&gt; (
    
  ));
};

urql

A highly customizable and versatile GraphQL client for React

MIT
Latest version published 17 days ago

Package Health Score

98 / 100
Full package analysis