Skip to main content

usePagesPublic

Hook to fetch the list of published pages.
It won't return pages with status "DRAFT".

Arguments

The usePagesPublic hook accepts an optional configuration object with the following props:

{
type?: string
types?: string[]
tag?: string
language?: string
usePagination?: boolean
page?: number
pageSize?: number
sort?: string
filterBy?: { [key: string]: any}
}
PropertyDefinition
typeOptional string to return only the pages with the specified page type.
typesOptional array of strings to return only the pages with one of the specified page types.
tagOptional string to return only the pages with the specified tag.
languageOptional language for the page. If not specified, the default language will be used.
usePaginationIf true, it will consider the page and pageSize parameters and it will return paginated results
pageThe page number, in case of pagination
pageSizeThe page size, in case of pagination
sortSort parameter: currently it accepts only createdAt,-createdAt,publishedAt,-publishedAt
filterByUsed to filter by a custom field. The object should have a key for each field and the value that it should have (or an array of possible values). The queries on the fields are in logical AND. For example: { category: 'shoes', subcategory: ['snickers', 'running'] }. At the moment you cannot filter using a complex type (like an object) for the value, so really now it should be string or string[] }

Return value

The hook returns an object with { data, error, isFetching } and other properties.

data contains:

Usage example

const { data, error, isFetching } = usePages()
const { data, error, isFetching } = usePages({
type: 'products',
usePagination: true,
pageSize: 20,
page: 1,
})