import { AbstractFetchStrategy, EndpointParams, FetchOptions, FilterDataOptions } from '@10up/headless-core';
import { GetServerSidePropsContext, GetStaticPropsContext } from 'next';
import { PreviewData } from '../../handlers/types';
/**
* The supported options for {@link fetchHookData}
*/
export interface FetchHookDataOptions
{
/**
* This should match params passed to the hook on the client side.
*/
params?: P;
/**
* Optional. If set, the data will be filtered given {@link FilterDataOptions}
*/
filterData?: FilterDataOptions;
/**
* Optional. If set, will fowardh fetch options to the fetch strategy
*/
fetchStrategyOptions?: FetchOptions;
}
/**
* A function that implementeds data fetching on the server. This should be used in `getServerSideProps`
* or `getStaticProps`.
*
* Data fetching will be perfomed by the specified strategy and URL params will be automatically extracted
* from `context
*
* ## Usage
*
* ```ts
* export async function getServerSideProps(context) {
* try {
* const usePostsHook = await fetchHookData(usePosts.fetcher(),context);
*
* return addHookData([usePostsHook], {});
* } catch (e) {
* return handleError(e, context);
* }
* }
* ```
*
* @param fetchStrategy The fetch strategy to use. Typically this is exposed by the hook e.g: `usePosts.fetcher()`
* @param ctx The Next.js context, either the one from `getServerSideProps` or `getStaticProps`
* @param options See {@link FetchHookDataOptions}
*
* @returns An object with a key of `data` and a value of the fetched data.
*
* @category Next.js Data Fetching Utilities
*/
export declare function fetchHookData(fetchStrategy: AbstractFetchStrategy, ctx: GetServerSidePropsContext | GetStaticPropsContext, options?: FetchHookDataOptions): Promise<{
key: string;
data: import("@10up/headless-core").FetchResponse;
isMainQuery: boolean;
}>;