usePageContext()
Environment: server, client.
Implemented by: UI framework Vike extension vike-react
/vike-vue
/vike-solid
(or yourself).
The usePageContext()
hook enables any UI component to access the pageContext
object.
Without vike-{react,vue,solid}
In case you don't use a UI framework Vike extension vike-react
/vike-vue
/vike-solid
, you can implement usePageContext()
yourself.
React
You can use React Context to make pageContext
accessible from any React component.
Examples:
- JavaScript: /boilerplates/boilerplate-react/renderer/usePageContext.jsx
- TypeScript: /boilerplates/boilerplate-react-ts/renderer/usePageContext.tsx
Vue 3 - Composition API
You can use
app.provide()
with
inject()
to make pageContext
accessible from any Vue component.
You can also implement a usePageContext()
component hook:
Examples:
- JavaScript: /boilerplates/boilerplate-vue/renderer/usePageContext.js
- TypeScript: /boilerplates/boilerplate-vue-ts/renderer/usePageContext.ts
Vue 3 - globalProperties
Alternatively, you can make pageContext
available to all Vue components by using app.config.globalProperties.
Example: /boilerplates/boilerplate-vue/.
Vue 2
For Vue 2 you can use Vue.prototype.