# State Nuxt provides `useState` to create a globally shared state within the context. `useState` is SSR-friendly `ref` replacement in that its value will be hydrated (preserved) after server-side rendering and is shared across all components using a unique key. ::alert{icon=⚠️} Never define `const state = ref()` outside of ` ``` ## Example In this example, we use a server-only plugin to find about request locale. ```ts [composables/states.ts] export const useLocale = () => useState('locale', () => 'en') ``` ```ts [plugins/locale.server.ts] export default defineNuxtPlugin((nuxtApp) => { const locale = useLocale() locale.value = nuxtApp.ssrContext?.req.headers['accept-language']?.split(',')[0] }) ``` ```vue [app.vue] ```