Skip to content

Instantly share code, notes, and snippets.

@rxgx
Last active September 18, 2019 05:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rxgx/6c2d4313de088b96272f3fb2a4914d21 to your computer and use it in GitHub Desktop.
Save rxgx/6c2d4313de088b96272f3fb2a4914d21 to your computer and use it in GitHub Desktop.
Apollo HoC to Hooks
import React from 'react';
import { useQuery, QueryHookOptions } from '@apollo/react-hooks';
import ErrorBoundary from 'components/ErrorBoundary';
import PagePreloader from 'components/PagePreloader';
import getVendors from 'pages/Admin/queries/getVendors';
import VendorListTable from './VendorListTable';
const options: QueryHookOptions = {
fetchPolicy: 'no-cache',
variables: { isCorporate: true },
};
export default function VendorList(props: any) {
const { loading, data, error } = useQuery(getVendors, options);
// show preloaded if loading
if (loading) return <PagePreloader />;
// display error if data error
if (error) return <ErrorBoundary error={error} />;
// we have the data, show the vendors table
return <VendorListTable vendors={data.vendors} {...props} />;
}
import { compose, withProps } from 'recompose';
import { graphql } from '@apollo/react-hoc';
import getVendors from 'pages/Admin/queries/getVendors';
import withGraphData from 'utils/withGraphData';
import PagePreloader from 'components/PagePreloader';
import VendorList from './VendorList';
export default compose(
graphql(getVendors, {
options: { fetchPolicy: 'no-cache', variables: { isCorporate: true } },
}),
withGraphData(PagePreloader),
withProps(props => ({ vendors: props.data.vendors }))
)(VendorList);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment