fetchPage

The fetchPage function is useful when you want to retrieve the content of one page from outside the React context (where you could use the usePage hook instead).

In particular, this comes in handy during the build process of a static website. Indeed, this is the method used in our Gatsby and Next.js starter projects.

Signature

const fetchPage = async (slug: string, apiKey: string): Promise<types.Page>
PropertyDefinition
pageSlugThe slug (string) of the page to fetch.
apiKeyApi Key of your React Bricks app (a string).

Return value

fetchPage returns a promise which resolves to a Page

Before using this page with ReactBricks' PageViewer component, you need to parse it with the cleanPage function.

Usage example

fetchPage('about-us', 'API_KEY').then((data) => {
const myPage = cleanPage(data, pageTypes, bricks)
console.log(myPage.content)
})