Querying first element with [0] not working in app but in Vision

46 Views Asked by At

I have kind of a singleton document in Sanity that features the content of the home page. When I try to query the type home document with [0] to get the first element I always get null as response. However, the same query works fine in Vision.

export const HOME_QUERY = groq`*[_type == "home"][0]`;

export async function getHome(): Promise<Home> {
    const data = await client.fetch(HOME_QUERY);
    return data;
}

Trying to use the home content, but getting an error because content is null. If I remove [0] from my GROQ query it works fine.

export default async function Home() {
  const content = await getHome();

  return (
    <main className="flex items-center justify-center min-h-screen">
      <h1 className="text-4xl">{content.title}</h1>
    </main>
  );
}

This is my client

import { createClient } from "@sanity/client/stega";

import { apiVersion, dataset, projectId, useCdn } from "../env";

export const client = createClient({
  apiVersion,
  dataset,
  projectId,
  useCdn,
  // These settings will be overridden in
  // ./sanity/lib/store.ts when draftMode is enabled
  perspective: "published",
  stega: {
    enabled: false,
    studioUrl: "/cms",
  },
});

Query in Vision

enter image description here

0

There are 0 best solutions below