Skip to content

Latest commit

 

History

History
33 lines (29 loc) · 587 Bytes

useSubscription.md

File metadata and controls

33 lines (29 loc) · 587 Bytes
id title
use-subscription
useSubscription
import { useMemo } from 'react';
import { useSubscription, graphql } from 'relay-hooks';

const subscriptionSpec = graphql`
  subscription TodoSubscription {
    todos {
      node {
        id
        text
        complete
      }
    }
  }
`;

const TodoList = (props) => {
  // NOTE: This will re-subscribe every render if config is not memoized. Please
  // do not pass an object defined inline.
  useSubscription(
    useMemo(() => ({
      subscription: subscriptionSpec,
      variables: {}
    }), [])
  );

  // ???
};