React Bricks

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 editor

Arguments

page

The page object, of type Page

pageTypeSchema

The pageType schema, of type IPageType[], as defined here.

blockTypeSchema

The 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, pageTypeSchema, blockTypeSchema)
  console.log(myPage.content)
})