Morrys Repositories

Morrys Repositories

  • Docs
  • GitHub

›API Reference

Relay Hooks

  • Getting Started

API Reference

  • useFragment
  • useRefetchable
  • usePagination
  • useMutation
  • useSubscription
  • usePreloadedQuery

usePreloadedQuery

sample project with nextjs and SSR

loadQuery

  • input parameters

same as useQuery + environment

  • output parameters
    • next: ( environment: IEnvironment, gqlQuery: GraphQLTaggedNode, variables?: TOperationType['variables'], options?: QueryOptions, ) => Promise<void>: fetches data. A promise returns to allow the await in case of SSR
    • dispose: () => void: cancel the subscription and dispose of the fetch
    • subscribe: (callback: (value: any) => any) => () => void: used by the usePreloadedQuery
    • getValue: (environment?: IEnvironment) => RenderProps<TOperationType> | Promise<any>: used by the usePreloadedQuery
import {graphql, loadQuery} from 'relay-hooks';
import {environment} from ''./environment';

const query = graphql`
  query AppQuery($id: ID!) {
    user(id: $id) {
      name
    }
  }
`;

const prefetch = loadQuery();
prefetch.next(
  environment,
  query,
  {id: '4'},
  {fetchPolicy: 'store-or-network'},
);
// pass prefetch to usePreloadedQuery()

loadLazyQuery

is the same as loadQuery but must be used with suspense

usePreloadedQuery

  • input parameters

    • loadQuery | loadLazyQuery
  • output parameters

    • same as useQuery
function Component(props) {
  data = usePreloadedQuery(props.prefetched);
  return data;
}
Last updated on 23/5/2020 by morrys
← useSubscription
Morrys Repositories
Docs
about relay-hooks
Community
User Showcase
More
GitHubStar
Follow @m0rrys
Facebook Open Source
Copyright © 2022 Lorenzo Di Giacomo