From e03afbd980f4e0226136b3324c6f166ec8a18a8e Mon Sep 17 00:00:00 2001
From: "Fred K. Schott"
Date: Sun, 21 Mar 2021 16:16:18 -0700
Subject: [PATCH] add fetch support
---
examples/snowpack/astro/pages/news.hmx | 8 +++++++-
examples/snowpack/snowpack.config.js | 7 ++++---
package-lock.json | 5 +++++
package.json | 1 +
src/transform2.ts | 3 ++-
5 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/examples/snowpack/astro/pages/news.hmx b/examples/snowpack/astro/pages/news.hmx
index cdccace95..f1350ed3f 100644
--- a/examples/snowpack/astro/pages/news.hmx
+++ b/examples/snowpack/astro/pages/news.hmx
@@ -9,7 +9,8 @@
import news from '../data/news.json';
import users from '../data/users.json';
- export function setup({ context, request }) {
+ export async function setup({ context, request, fetch }) {
+ const pokemonData = await fetch(`https://pokeapi.co/api/v2/pokemon/ditto`);
return {
context: {
title: 'Community & News',
@@ -18,6 +19,7 @@
// Add your project, organization, or company to the end of this list!
news,
users,
+ pokemonData: await pokemonData.json(),
}
}
}
@@ -37,6 +39,10 @@
Submit it!
+
+ In case you're curious, the best pokemon is {context.pokemonData.name}.
+
+