# 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 ` ``` ```ts [composables/states.ts] export const useColor = () => useState('color', () => 'pink') ``` :: ## Example In this example, we use a [server-only plugin](/docs/directory-structure/plugins) to find about request locale. ::code-group ```vue [app.vue] ``` ```ts [composables/states.ts] export const useLocale = () => useState('locale', () => 'en') ``` ```ts [plugins/locale.server.ts] export default defineNuxtPlugin((nuxtApp) => { const locale = useLocale() locale.value = locale.value ?? nuxtApp.ssrContext?.req.headers['accept-language']?.split(',')[0] }) ``` :: :button-link[Full example on StackBlitz]{href="https://stackblitz.com/github/nuxt/framework/tree/main/examples/use-state?terminal=dev" blank}