React Bricks

fetchPages


The fetchPages function is useful when you want to retrieve all your pages from outside the React context (where you could use the usePages hook).

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

Arguments

apiKey

Api Key of your React Bricks app (a string)

options

Optional object to filter the pages by type or tag (see below)

Options

The options object has the following shape

{
  type?: string;
  tag?: string;
}
type

Optional string to return only the pages with the specified page type

tag

Optional string to return only the pages with the specified tag

Return value

fetchPages returns a promise which resolves to an array of pages
The pages are of type Page, but without the content field.

To retrieve the content of each page, you can use the fetchPage function.

Usage example

fetchPages('API_KEY', { type: 'blogPost', tag: 'react' })
.then(data => {
  ...
})