get-started-sanity-sveltekit's Issues
Documentation of Sanity.io is wrong in combination with this example
Describe the bug
data cant be fetched/correctly displayed due to syntax error
To Reproduce
Steps to reproduce the behavior:
- Go to '...'
- Follow tutorial by copying the exact code:
// src/routes/+page.js
import {createClient} from "@sanity/client";
const client = createClient({
projectId: "[ your project ID ]",
dataset: "[ your preferred dataset, eg production ]",
apiVersion: "2021-10-21",
useCdn: false
});```
```javascript// /src/routes/+page.js
import {createClient} from "@sanity/client";
const client = createClient({
projectId: "[ your project ID ]",
dataset: "production",
apiVersion: "2021-10-21",
useCdn: false
});
export async function load({ params }) {
const data = await client.fetch(`*[_type == "pet"]`);
if (data) {
return {
pets: data
};
}
return {
status: 500,
body: new Error("Internal Server Error")
};
}
<!-- /src/routes/+page.svelte -->
<script>
export let data;
</script>``
```javascript
{#if pets && pets.length}
<ul>
{#each pets as pet}
<li>{pet.name}</li>
{/each}
</ul>
{:else}
<p>No pets found.</p>
{/if}
Expected behavior
According to docs, the fetched pets array should be displayed in html
Screenshots
not needed to replicate this error if following the tutorial exactly as described on the website
Which versions of Sanity are you using?
@sanity/cli (global) 3.19.1 (up to date)
What operating system are you using?
Linux Debian 12
Which versions of Node.js / npm are you running?
latest
Additional context
what fixed it for me was the following code snipped used as page.svelte instead:
<script>
export let data
let pets = [
];
pets = data.pets
</script>
<header>
<h1>Sanity + SvelteKit</h1>
</header>
<main>
<h2>Pets</h2>
{#if pets && pets.length}
<ul>
{#each pets as animal}
<li>{animal.name}</li>
{/each}
</ul>
{:else}
<p>No pets to show</p>
{/if}
<h2>Data</h2>
<div>
{#if pets && pets.length}
<pre>
{JSON.stringify(pets, null, 2)}
</pre>
{:else}
<p>Your data will show up here when you've configured everything correctly</p>
{/if}
</div>
</main>
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.