mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
32 lines
588 B
JavaScript
32 lines
588 B
JavaScript
|
import { Query } from 'graphql-react'
|
||
|
|
||
|
export default () => (
|
||
|
<Query
|
||
|
loadOnMount
|
||
|
loadOnReset
|
||
|
fetchOptionsOverride={options => {
|
||
|
options.url = 'https://graphql-pokemon.now.sh'
|
||
|
}}
|
||
|
operation={{
|
||
|
query: /* GraphQL */ `
|
||
|
{
|
||
|
pokemon(name: "Pikachu") {
|
||
|
name
|
||
|
image
|
||
|
}
|
||
|
}
|
||
|
`
|
||
|
}}
|
||
|
>
|
||
|
{({ data, loading }) =>
|
||
|
data ? (
|
||
|
<img src={data.pokemon.image} alt={data.pokemon.name} />
|
||
|
) : loading ? (
|
||
|
<p>Loading…</p>
|
||
|
) : (
|
||
|
<p>Error!</p>
|
||
|
)
|
||
|
}
|
||
|
</Query>
|
||
|
)
|