-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathAnnouncementBarPage.tsx
54 lines (47 loc) · 1.23 KB
/
AnnouncementBarPage.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* Quickstart snippet
* snippets/hydrogen/app/components/AnnouncementBarPage.tsx
*/
import {Content, fetchOneEntry} from '@builder.io/sdk-react';
import type {LoaderFunction} from '@remix-run/node';
import {useLoaderData} from '@remix-run/react';
import {useNonce} from '@shopify/hydrogen';
const BUILDER_API_KEY = 'ee9f13b4981e489a9a1209887695ef2b';
const model = 'announcement-bar';
export const announcementsLoader: LoaderFunction = async ({
params,
request,
}) => {
try {
const pathname = `/announcements/${params['*'] || ''}`;
const url = new URL(request.url);
const content = await fetchOneEntry({
model,
apiKey: BUILDER_API_KEY,
userAttributes: {
urlPath: pathname,
},
});
return {content, model};
} catch (e) {
console.error(e);
return {content: null};
}
};
export default function AnnouncementBarPage() {
const {content, model} = useLoaderData<{content: any; model: string}>();
const nonce = useNonce();
return (
<div>
{content && (
<Content
model={model}
apiKey={BUILDER_API_KEY}
content={content}
nonce={nonce}
/>
)}
<div>The rest of your page goes here</div>
</div>
);
}