-
Notifications
You must be signed in to change notification settings - Fork 0
/
NostoHome.tsx
50 lines (46 loc) · 1.57 KB
/
NostoHome.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
import { useNostoContext } from "./context"
import { useNostoApi } from "../utils/hooks"
/**
* The `NostoHome` component must be used to personalise the home page. The component does not require any props.
*
* By default, your account, when created, has four front-page placements named `frontpage-nosto-1`, `frontpage-nosto-2`, `frontpage-nosto-3` and `frontpage-nosto-4`.
* You may omit these and use any identifier you need.
* The identifiers used here are simply provided to illustrate the example.
*
* The `<NostoHome \>` component needs to be added after the placements.
* Content and recommendations will be rendered through this component.
*
* @example
* ```
* <div className="front-page">
* <NostoPlacement id="frontpage-nosto-1" />
* <NostoPlacement id="frontpage-nosto-2" />
* <NostoPlacement id="frontpage-nosto-3" />
* <NostoPlacement id="frontpage-nosto-4" />
* <NostoHome />
* </div>
* ```
*
* @group Components
*/
export default function NostoHome(props: { placements?: string[] }) {
const { recommendationComponent, useRenderCampaigns } = useNostoContext()
const { renderCampaigns, pageTypeUpdated } = useRenderCampaigns("home")
useNostoApi(
async (api) => {
const data = await api.defaultSession()
.viewFrontPage()
.setPlacements(props.placements || api.placements.getPlacements())
.load()
renderCampaigns(data, api)
},
[recommendationComponent, pageTypeUpdated]
)
return (
<>
<div className="nosto_page_type" style={{ display: "none" }}>
front
</div>
</>
)
}