Created
August 11, 2019 09:49
-
-
Save bartcis/be0611e017e2432a8ac6ad5c627b3b01 to your computer and use it in GitHub Desktop.
This file contains 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 } from 'graphql-hooks'; | |
const countryQuery = ` | |
query($id: Int!) { | |
country(id: $id) { | |
name | |
population | |
} | |
} | |
` | |
const HookQuery = ({countryId}) => { | |
const params = { | |
id: Number(countryId) | |
} | |
const { loading, error, data } = useQuery(countryQuery, { | |
variables: params, | |
}); | |
if (loading) return <div>Loading...</div> | |
if (error) return <div>ERRRORRR</div> | |
return ( | |
<> | |
<h1>Hook response:</h1> | |
<div className='container'> | |
<p className='container__item'> | |
<span><b>Country:</b></span> | |
<span><b>Population:</b></span> | |
</p> | |
<p className='container__item' key={data.country.id}> | |
<span dangerouslySetInnerHTML={{ __html: data.country.name }}></span> | |
<span dangerouslySetInnerHTML={{ __html: data.country.population }}></span> | |
</p> | |
</div> | |
</> | |
); | |
}; | |
export default HookQuery; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment