hooks.useContent
Functions¶
useContent()¶
Call Signature¶
useContent\<
T>():T
Defined in: hooks/useContent.tsx:52
Returns a proxy for accessing your page's content e.g, index.json.props,
show.json.props, etc.
{
data: {
body: {
cart: {__id: 'user_cart'}
},
footer: {title: "welcome"}},
},
fragments: {user_cart: {total: 100}}
}
The proxy will lazily and automatically resolve any FragmentRefs making it
as easy as
The hook will also automatically tracks fragment dependencies and triggers re-renders only when accessed fragments change.
Type Parameters¶
| Type Parameter | Default type | Description |
|---|---|---|
T |
JSONMappable |
The data type being accessed (defaults to JSONMappable) |
Returns¶
T
Reactive proxy to page data
Example¶
// Access current page data
const page = useContent()
// Access a specific page's data by key
const posts = useContent('/posts')
Call Signature¶
useContent\<
T>(pageKey?:string):undefined|T
Defined in: hooks/useContent.tsx:57
Type Parameters¶
| Type Parameter | Default type |
|---|---|
T |
JSONMappable |
Parameters¶
| Parameter | Type | Description |
|---|---|---|
pageKey? |
string |
Optional page key to access a specific page's data. When omitted, returns data for the current page. |
Returns¶
undefined | T
unproxy()¶
unproxy\<
T>(proxy:T):Unproxy\<T>
Defined in: hooks/useContent.tsx:127
Extracts the underlying state from an useContent proxy
Type Parameters¶
| Type Parameter |
|---|
T |
Parameters¶
| Parameter | Type |
|---|---|
proxy |
T |
Returns¶
Unproxy\<T>