usePreviewMode documentation for more information on how it works under the hood.The useStatamicPreviewMode composable is used to handle the Statamic preview mode. It will automatically create a preview mode token based on the current route. It uses the usePreviewMode composable from nuxt under the hood.
This is used to set the preview token as a parameter in the request URL, for example inside the useStatamicApi composable.
export function useStatamicApi() {
// ...
const previewMode = useStatamicPreviewMode();
const livePreviewToken = computed(() => previewMode.enabled.value ? previewMode.state.token : "");
const baseParams = computed((): Partial<StatamicApiParamsMultiple> => ({ token: livePreviewToken.value }));
// ...
}
function useStatamicPreviewMode(): ReturnType<typeof usePreviewMode>
shouldEnable function that checks if preview mode should be enabled based on the query parameters.The
shouldEnablefunction checks if preview mode should be enabled based on the query parameters. It will returntrueif thelive-previewquery parameter is present or thepreviewquery parameter is set totrue.