cleanPage

The cleanPage function prepares the page content retrieved by React Bricks APIs to be used in the PageViewer component.

It does two things:

  • It removes all the invalid blocks (unknown in the schema or not allowed for this page type)
  • It transforms the JSON content of every (rich)text prop into the JavaScript structure needed by the text viewer component

Signature

const cleanPage = (
page: types.Page,
pageTypes: types.IPageType[],
bricks: types.Bricks
): types.Page
PropertyDefinition
pageThe page object, of type Page.
pageTypesThe pageType schema, of type IPageType[], as defined here.
bricksThe blocks schema, of type IBlockType[], as defined here.

Return value

cleanPage returns an object of type Page, with the clean content and the invalidBlocksTypes array containing the name of each invalid block that was removed.

Usage example

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