Skip to content

Instantly share code, notes, and snippets.

@anartzdev
Created March 7, 2023 06:32
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 anartzdev/eb085005cb7ded4003fc7576bc64f71a to your computer and use it in GitHub Desktop.
Save anartzdev/eb085005cb7ded4003fc7576bc64f71a to your computer and use it in GitHub Desktop.
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