React Bricks


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

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.



The slug (string) of the page to fetch


Api 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, pageTypeSchema, blockTypeSchema)