-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathAnnouncementBar.tsx
51 lines (46 loc) · 1.14 KB
/
AnnouncementBar.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
/**
* https://www.builder.io/c/docs/integrate-section-building
* https://www.builder.io/c/blueprints/announcement-bar
* src/components/AnnouncementBar.tsx
*/
import {
Content,
fetchOneEntry,
type BuilderContent,
} from '@builder.io/sdk-react';
import { useEffect, useState } from 'react';
const BUILDER_API_KEY = 'ee9f13b4981e489a9a1209887695ef2b';
const MODEL_NAME = 'announcement-bar';
export default function AnnouncementBar() {
const [content, setContent] = useState<BuilderContent | null>(null);
useEffect(() => {
fetchOneEntry({
model: MODEL_NAME,
apiKey: BUILDER_API_KEY,
userAttributes: {
urlPath: window.location.pathname,
},
})
.then((content) => {
if (content) {
setContent(content);
}
})
.catch((err) => {
console.log('Oops: ', err);
});
}, []);
return (
<>
{content && (
<Content
content={content}
model={MODEL_NAME}
apiKey={BUILDER_API_KEY}
/>
)}
{/* content coming from your app (or also Builder) */}
<div>The rest of your page goes here</div>
</>
);
}