diff --git a/samples/nextjs/src/Layout.tsx b/samples/nextjs/src/Layout.tsx
index f77e5ead0d..7c52c3a6d0 100644
--- a/samples/nextjs/src/Layout.tsx
+++ b/samples/nextjs/src/Layout.tsx
@@ -5,7 +5,6 @@ import { useI18n } from 'next-localization';
import { getPublicUrl } from 'lib/util';
import {
Placeholder,
- LayoutServiceData,
VisitorIdentification,
useSitecoreContext,
} from '@sitecore-jss/sitecore-jss-nextjs';
@@ -50,31 +49,24 @@ const Navigation = () => {
};
type LayoutProps = {
- layoutData: LayoutServiceData;
+ context: StyleguideSitecoreContextValue;
};
-const Layout = ({ layoutData }: LayoutProps): JSX.Element => {
+const Layout = ({ context }: LayoutProps): JSX.Element => {
const { updateSitecoreContext } = useSitecoreContext({ updatable: true });
// Update Sitecore Context if layoutData has changed (i.e. on client-side route change).
// Note the context object type here matches the initial value in [[...path]].tsx.
useEffect(() => {
- const context: StyleguideSitecoreContextValue = {
- route: layoutData.sitecore.route,
- itemId: layoutData.sitecore.route.itemId,
- ...layoutData.sitecore.context,
- };
updateSitecoreContext && updateSitecoreContext(context);
- }, [layoutData]);
+ }, [context]);
- const { route } = layoutData.sitecore;
+ const { route } = context;
return (
<>
-
- {(route.fields && route.fields.pageTitle && route.fields.pageTitle.value) || 'Page'}
-
+ {route?.fields?.pageTitle?.value || 'Page'}
diff --git a/samples/nextjs/src/pages/[[...path]].SSR.tsx b/samples/nextjs/src/pages/[[...path]].SSR.tsx
index 8911381e7e..f319481834 100644
--- a/samples/nextjs/src/pages/[[...path]].SSR.tsx
+++ b/samples/nextjs/src/pages/[[...path]].SSR.tsx
@@ -18,7 +18,7 @@ const SitecorePage = ({ notFound, layoutData, componentProps }: SitecorePageProp
handleExperienceEditorFastRefresh();
}, []);
- if (notFound || !layoutData) {
+ if (notFound || !layoutData?.sitecore?.route) {
// Shouldn't hit this (as long as 'notFound' is being returned below), but just to be safe
return ;
}
@@ -35,7 +35,7 @@ const SitecorePage = ({ notFound, layoutData, componentProps }: SitecorePageProp
componentFactory={componentFactory}
context={context}
>
-
+
);
diff --git a/samples/nextjs/src/pages/[[...path]].tsx b/samples/nextjs/src/pages/[[...path]].tsx
index 2f4a616f8d..69a20b96cd 100644
--- a/samples/nextjs/src/pages/[[...path]].tsx
+++ b/samples/nextjs/src/pages/[[...path]].tsx
@@ -19,7 +19,7 @@ const SitecorePage = ({ notFound, layoutData, componentProps }: SitecorePageProp
handleExperienceEditorFastRefresh();
}, []);
- if (notFound || !layoutData) {
+ if (notFound || !layoutData?.sitecore?.route) {
// Shouldn't hit this (as long as 'notFound' is being returned below), but just to be safe
return ;
}
@@ -36,7 +36,7 @@ const SitecorePage = ({ notFound, layoutData, componentProps }: SitecorePageProp
componentFactory={componentFactory}
context={context}
>
-
+
);