Safely run pre-hydration steps on the client with Nuxt 3
Install and add nuxt-pre-hydrate to your nuxt.config.
# Whichever matches your package manager
pnpm add -D nuxt-pre-hydrate
npm install -D nuxt-pre-hydrate
yarn add -D nuxt-pre-hydrate
export default defineNuxtConfig({
modules: ['nuxt-pre-hydrate'],
})
To use, you can use the <PreHydrate> component anywhere in your app.
<script setup lang="ts">
const contentRenderer = (renderProps) => /* return a string of the HTML meant to be rendered on the client */
</script>
<template>
<PreHydrate tag="div" :renderContent="contentRenderer" strategy-name="test" v-bind="renderProps">
{{ contentRenderer() }}
</PreHydrate>
</template>
corepack enable (use npm i -g corepack for Node.js < 16.10)pnpm installpnpm dev:preparepnpm dev to start playground in development modeMade with ❤️
Published under the MIT License.
We use cookies
We use cookies to analyze traffic and improve your experience. You can accept or reject analytics cookies.