Sanity Library Reference Docs
    Preparing search index...
    DefinedFetchType: <const QueryString extends string>(
        options: {
            params?: QueryParams | Promise<QueryParams>;
            perspective?: LivePerspective;
            query: QueryString;
            requestTag?: string;
            stega?: boolean;
            tags?: string[];
        },
    ) => Promise<
        {
            data: ClientReturn<QueryString, unknown>;
            sourceMap: ContentSourceMap | null;
            tags: string[];
        },
    >

    Fetches data through the configured Sanity client and returns the result together with the source map and cache tags that Sanity Live uses for targeted revalidation.

    Returned by defineLive({strict: false}) and defineLive({strict: undefined}).

    Type declaration

      • <const QueryString extends string>(
            options: {
                params?: QueryParams | Promise<QueryParams>;
                perspective?: LivePerspective;
                query: QueryString;
                requestTag?: string;
                stega?: boolean;
                tags?: string[];
            },
        ): Promise<
            {
                data: ClientReturn<QueryString, unknown>;
                sourceMap: ContentSourceMap | null;
                tags: string[];
            },
        >
      • Type Parameters

        • const QueryString extends string

        Parameters

        • options: {
              params?: QueryParams | Promise<QueryParams>;
              perspective?: LivePerspective;
              query: QueryString;
              requestTag?: string;
              stega?: boolean;
              tags?: string[];
          }
          • Optionalparams?: QueryParams | Promise<QueryParams>

            Parameters used by the GROQ query.

          • Optionalperspective?: LivePerspective

            Content perspective used for the fetch.

            Requires serverToken to be configured in defineLive()

            The default is 'published' unless

            • Cache Components are disabled
            • defineLive() was given a serverToken
            • defineLive() is not set to strict: true
            • draftMode() is enabled

            If all of the above conditions are met, then the default value will be resolved from attempting to read the 'sanity-preview-perspective' cookie and fall back to 'drafts' if not set

          • query: QueryString

            GROQ query to execute.

          • OptionalrequestTag?: string

            Request tag used to identify the request in Sanity Content Lake logs.

            If cacheComponents: true then the default value is 'next-loader.fetch.cache-components' otherwise it's 'next-loader.fetch'

          • Optionalstega?: boolean

            Enables stega encoding of the data. This is typically only used in draft mode with perspective: 'drafts' and @sanity/visual-editing.

            Requires serverToken to be configured in defineLive()

            The default is false unless

            • Cache Components are disabled
            • defineLive() was given a serverToken
            • defineLive() is not set to strict: true
            • defineLive() was given a client that defines stega.studioUrl
            • draftMode() is enabled

            If all of the above conditions are met, then the default value will be true

          • Optionaltags?: string[]

            Additional cache tags to associate with this fetch.

            The default behavior will always add cache tags automatically for the query based on the syncTags response returned by Content Lake. You only need to define custom tags if you also mutate content in a server action and need to implement read-your-own-write UI.

            When cacheComponents: false your custom tags are appended to the underlying next.tags array on the fetch request and are subject to the tag length and max tag items limits of Next.js.

        Returns Promise<
            {
                data: ClientReturn<QueryString, unknown>;
                sourceMap: ContentSourceMap | null;
                tags: string[];
            },
        >