usePageValues
The usePageValues
hook allows you to access and modify page meta values within your bricks.
Usage Example
// The returned array contains the Page values and a setter functionconst [page, setPage] = usePageValues()
return ( <div> {/* Access the page creation date */} <p>Created at {moment(page.createdAt).format('MM/DD/YYYY')}.</p>
{/* Access the page title */} <p>Page title: {page.meta.title}</p>
{/* Access a custom field's value */} <p>Page title: {page.customValues.productId}</p> </div>)
Hook Signature
const usePageValues = (): [ types.PageValues, (pageData: types.PartialPage) => void]
The usePageValues
is called without arguments.
It returns an array containing the page values and a setter function: [pageValues, setPageValues]
.
pageValues
is an object with the structure shown belowsetPageValues
is a function to set the values (merging the object one level deep).
Returned Values
The returned object has the following structure:
type PageValues = { id: string type: string name: string slug: string meta: IMeta customValues?: Props externalData?: Props authorId?: string author: Author status: PageStatus editStatus: EditStatus isLocked: boolean tags: string[] category?: string createdAt: string publishedAt?: string scheduledForPublishingOn?: string language: string translations: Translation[] lastEditedBy: LastEditedBy}
For more details, refer to the following type definitions: