Skip to main content

Other changes

Hooks replacements for server components

isAdmin

isAdmin(): boolean

Function which returns true if execution runs inside the Admin interface, false otherwise.

It replaces the useAdminContext hook, not available for server components.

getPageValues

getPageValues(): types.PageValues | null

Function which returns the pageValues of the current page.

It replaces the usePageValues hook, not available for server components.

For client components

For a complete usage example, see Interactive bricks

register

register(config: types.ReactBricksConfig): void

Function that initializes the React Bricks configuration so that it is available to render the page with RSC. This function should be invoked before using any component or function imported from react-bricks/rsc.

wrapClientComponent

wrapClientComponent<T>({
ClientComponent: React.FC<T>,
RegisterComponent: React.FC<any>,
schema: types.IBlockType<T>,
}): types.Brick<T>

Function which wraps a client component (a component with 'use client') and, adding the schema, returns a React Bricks' brick. RegisterComponent is a function from react-bricks/rsc/client.

Meta data

getMetadata

getMetadata(page: types.Page): IMetadata

Next.js 14+ with the App Router has its way of managing meta data. This function returns the page metadata so that they are compatible with Next.js Metadata.

fetchPagePreview

fetchPagePreview({
  token: string
  config: types.ReactBricksConfig
  fetchOptions?: types.FetchOptions
}): Promise<types.Page>

Function which fetches the page data so that it can be viewed in a preview link.

It is an alternative solution to the <Preview> component used in the non-RSC library.

Other functions

getBlockValue

getBlockValue(propName: string): any | null

Function which returns the value of the propName for the current block in a server component.

getBricks

getBricks(): types.Bricks

Function to get all the configuration's bricks in a server component.

Under react-bricks/rsc/client

RegisterComponent

RegisterComponent: React.FC<RegisterComponentProps>

type RegisterComponentProps = { page: types.Page; block: types.IContentBlock }

Function to be used together with wrapClientComponent to create bricks from client components.

ClickToEdit

ClickToEdit: React.FC<ClickToEditProps>

interface ClickToEditProps {
pageId: string
language?: string
editorPath: string
clickToEditSide?: types.ClickToEditSide
}

Client component that shows the icon to edit the page when a user is viewing the frontend website while logged in the admin interface.