onAfterRenderHtml()
hook
Environment: server.
Implemented by: vike-react
/vike-vue
.
You need
vike-react
/vike-vue
to be able to useonAfterRenderHtml()
.
Hook called right after rendering the +Page
component to HTML.
It's called upon rendering the first page.
- It's called regardless of whether SSR is disabled. (The first page the user visits is always rendered to HTML: when SSR is disabled then the HTML is just an HTML shell that doesn't contain the content of the page.)
- It isn't called upon page navigation. (Pages aren't rendered to HTML upon page navigation.)
Conditionally
If you want to apply onAfterRenderHtml()
only for SSR then check whether pageContext.Page
is set:
pageContext
Commonly used pageContext
properties inside onAfterRenderHtml()
:
Use cases
It's usually used for integrating tools, such as dehydrating state management libraries.