Pass server state to client in Nuxt and name the composable

This tests Nuxt SSR state hydration. A strong answer names useState, explains server values serialize to JSON for client hydration, and warns against refs defined outside setup.
What's really being asked
Whether you understand how Nuxt bridges server and client state during SSR without duplicate data fetching. The interviewer wants to know if you grasp hydration, serialization boundaries, and server request isolation.
The full answer
Four things in order. First, name useState as the key composable and describe it as an SSR-friendly ref replacement. Second, explain the hydration flow: the server runs useState, serializes the value into the HTML payload as JSON, and the client picks up that exact value on hydration instead of re-fetching. Third, stress the serialization constraint because the payload is JSON, meaning no classes, functions, or symbols can live inside useState. Fourth, mention the unique key requirement so multiple components share the same reactive state, and contrast this with a plain ref defined outside setup which creates shared mutable state across concurrent server requests and leads to memory leaks.
The mistakes people make
Suggesting a global const state = ref({}) in a module file. This is dangerous in Nuxt because the same module instance is reused across requests on the server, causing cross-user data leakage. Another red flag is jumping straight to Pinia without explaining how its state reaches the client; Pinia works but only if you understand it relies on the same underlying serialization and hydration. Also, claiming useState avoids serialization or handles non-JSON data.
What usually comes next
How would you initialize state asynchronously on the server once per app load? The expected answer is callOnce inside app.vue. What happens if you mutate useState on the client after hydration? The answer is it becomes reactive and updates components normally. How do you invalidate cached state globally? Mention clearNuxtState. When is Pinia preferable over useState? Pinia shines for complex cross-component logic, while useState is ideal for simple shared SSR state.
A concrete example
Suppose you fetch a website configuration object from a CMS. On the server, inside a composable or app.vue, you write const config = useState('website-config', async () => await $fetch('/api/config')). The server executes the fetch, populates config.value, and Nuxt serializes that object into the rendered HTML. When the browser hydrates, the client script reads the serialized JSON, injects it into useState('website-config'), and the page renders instantly without a second network request. If a plain ref were used instead and exported from a shared file, every concurrent visitor would overwrite the same server-side object.
Interview question
Why is defining a shared reactive state with ref outside setup in a Nuxt module file dangerous during SSR?
- a.Nuxt removes refs defined outside setup from the serialized HTML payload.
- b.It blocks useState from registering a unique key for that state across components.
- c.The ref loses reactivity when the client hydrates the application.
- d.The module singleton is reused across concurrent server requests, leading to cross-user data leakage.Correct
Why? this is the answer
Because Nuxt reuses the module singleton across requests, a global ref becomes shared mutable state that can leak data between concurrent users. Option C is tempting because SSR often involves hydration problems, but the real issue is server-side cross-request contamination, not client reactivity.
Just read this? Test yourself on what you have been reading.
Read the original → nuxt.com
- #nuxt
- #ssr
- #vue
- #state-management
- #hydration
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.
See open roles