Skip to content

Instantly share code, notes, and snippets.

@ilhamsa1
Last active July 5, 2020 13:12
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 ilhamsa1/21b935c60207f5d372454532ed383d9c to your computer and use it in GitHub Desktop.
Save ilhamsa1/21b935c60207f5d372454532ed383d9c to your computer and use it in GitHub Desktop.
implementasion to use Graphql reusable components
import React from 'react'
import { useQuery } from '@apollo/react-hooks'
import { LoadingDots } from 'site_library/components'
const Query = ({ children, query, id, where }) => {
const { data, loading, error } = useQuery(query, {
variables: {
id,
where,
},
})
if (loading) {
return (
<div style={{ margin: '170px' }}>
<LoadingDots />
</div>
)
}
if (error) {
return (
<p>
Error: {JSON.stringify(error)}
</p>
)
}
return children({ data })
}
export default Query
import React from 'react'
import Head from 'next/head'
import Query from '../../../components/query'
import { productServices as WILLS_LPA } from '../../../graphql/products'
import WillsLpa from '../../../components/product/wills-lpa'
const VARIABEL = {
slug: 'wills-lpa',
type: 'Personal',
}
const WillsLpa = () => {
return (
<>
<Head>
<title>Personal - Wills Lpa</title>
<meta name="description" content="Lawkin Landing Page" />
<meta name="theme-color" content="#2563FF" />
<meta name="keywords" content="Lawkin Landing Page" />
</Head>
<Query query={WILLS_LPA} where={VARIABEL}>
{({ data }) => {
return (
<WillsLpa content={data} />
)
}}
</Query>
</>
)
}
export default WillsLpa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment