Skip to content

Commit 03505dd

Browse files
committed
fix(web): fix hook order exception
closed COD-316
1 parent 68431ed commit 03505dd

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

apps/web/app/routes/_index.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { RenderBlocks } from '@codeware/shared/ui/payload-components';
2+
import type { SiteSetting } from '@codeware/shared/util/payload-types';
23
import { type MetaFunction, useRouteError } from '@remix-run/react';
34

45
import { Container } from '../components/container';
@@ -10,10 +11,22 @@ type LoaderError = {
1011
status: number;
1112
};
1213

13-
// TODO: How to use it properly?
14-
export const meta: MetaFunction = () => {
15-
const { landingPage } = useSiteSettings();
16-
return [{ title: landingPage?.name }];
14+
export const meta: MetaFunction = ({ matches }) => {
15+
// Get loading page from root loader data
16+
const rootData = matches.find((match) => match.id === 'root')?.data as Record<
17+
string,
18+
SiteSetting
19+
>;
20+
21+
let title = 'Home';
22+
23+
if (rootData && 'siteSettings' in rootData) {
24+
if (typeof rootData.siteSettings.general.landingPage === 'object') {
25+
title = rootData.siteSettings.general.landingPage.meta?.title ?? title;
26+
}
27+
}
28+
29+
return [{ title }];
1730
};
1831

1932
export default function Index() {

0 commit comments

Comments
 (0)