Last active
September 18, 2019 05:46
-
-
Save rxgx/6c2d4313de088b96272f3fb2a4914d21 to your computer and use it in GitHub Desktop.
Apollo HoC to Hooks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} />; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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