Skip to main content

Function: addHookData()

addHookData<P>(_hookStates, nextProps): object

Defined in: packages/next/src/data/server/addHookData.ts:74

The addHookData function is responsible for collecting all of the results from the fetchHookData function calls and prepares the shape of the data to match what the frameworks expects (such as setting initial values for SWR and collecting SEO data).

Usage​

export async function getServerSideProps(context) {
try {
const usePostsHook = await fetchHookData(usePosts.fetcher(),context);
const useAppSettingsHook = await fetchHookData(useAppSettings.fetcher(),context);
return addHookData([usePostsHook, useAppSettingsHook], {});
} catch (e) {
return handleError(e, context);
}
}

Type Parameters​

P​

P extends AddHookDataBaseProps

Parameters​

_hookStates​

HookState<FetchResponse<Entity | Entity[]>>[]

nextProps​

NextJSProps<P>

Any additional props to pass to Next.js page routes.

Returns​

object

notFound?​

optional notFound: boolean

props​

props: P & object

Type declaration​

__headstartwp_site​

__headstartwp_site: null | string

fallback​

fallback: object

seo​

seo: object

seo.yoast_head​

seo.yoast_head: string = seo

seo.yoast_head_json​

seo.yoast_head_json: YoastJSON

themeJSON​

themeJSON: object

redirect?​

optional redirect: Redirect

revalidate?​

optional revalidate: number | boolean