Created
March 7, 2023 06:32
-
-
Save anartzdev/eb085005cb7ded4003fc7576bc64f71a 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 { component$, Resource, useResource$ } from '@builder.io/qwik'; | |
import { countriesGraphQLAPI } from '~/api/countries-data'; | |
export default component$(() => { | |
const continentsListResource = useResource$<any>(({ cleanup }) => { | |
const controller = new AbortController(); | |
cleanup(() => controller.abort()); | |
return countriesGraphQLAPI( | |
{ | |
query: ` | |
{ | |
continents { | |
code | |
name | |
} | |
} | |
`, | |
}, | |
controller | |
); | |
}); | |
return ( | |
<> | |
<h1>Countries</h1> | |
<Resource | |
value={continentsListResource} | |
onPending={() => <div>Loading...</div>} | |
onRejected={() => <div>Failed to load continents list data</div>} | |
onResolved={({ continents }) => { | |
return continents.length ? ( | |
<ul> | |
{continents.map((continent: any) => ( | |
<li> | |
Code: {continent.code} / Name: {continent.name} | |
</li> | |
))} | |
</ul> | |
) : ( | |
<p>Sin resultados</p> | |
); | |
}} | |
/> | |
</> | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment