useHydration

Returns the isomorphic context object, aptly named hydration context.

Works isomorphically on client and server.

Vue

import { useHydration } from 'fastify-vite-vue/client'

const ctx = useHydration(config)

React

import { useHydration } from 'fastify-vite-react/client'

const [ctx, update] = useHydration(config)

In React an update function is also returned because ctx is not reactive like in the Vue version.

Config

The config object passed to useHydration is optional. It can either contain a reference to getPayload, which will cause $payload and $payloadPath to be included in the returned object — or a reference to getData, which will cause $data to be included in the returned object.

See the Data Fetching section on the Vue and React guides for more info.

Context

reqthe core Fastify request object — only available on the server
replythe core Fastify reply object — only available on the server
fastifythe Fastify server instance — only available on the server
$globalGlobal Data — available isomorphically
$payloadRoute Payload data — available isomorphically
$payloadPath()Route Payload endpoint — available isomorphically
$dataRoute Isomorphic Data — available isomorphically