RC
Getting Started Guide API Examples Community
  • Composables
    • useAsyncData
    • useCookie
    • useError
    • useFetch
    • useHead
    • useHydration
    • useLazyAsyncData
    • useLazyFetch
    • useNuxtApp
    • useRequestHeaders
    • useRoute
    • useRouter
    • useState
  • Components
    • <NuxtPage>
    • <NuxtLayout>
    • <NuxtLink>
    • <NuxtErrorBoundary>
  • Utils
    • $fetch
    • abortNavigation
    • addRouteMiddleware
    • clearError
    • defineNuxtComponent
    • defineNuxtRouteMiddleware
    • definePageMeta
    • navigateTo
    • refreshNuxtData
    • throwError
  • Advanced
    • Lifecycle Hooks
    • Kit Utilities
  • Commands
    • nuxi add
    • nuxi analyze
    • nuxi build
    • nuxi dev
    • nuxi generate
    • nuxi info
    • nuxi init
    • nuxi preview
    • nuxi typecheck
    • nuxi upgrade
  • Configuration
    • Nuxt Config
  • Composables
    • useAsyncData
    • useCookie
    • useError
    • useFetch
    • useHead
    • useHydration
    • useLazyAsyncData
    • useLazyFetch
    • useNuxtApp
    • useRequestHeaders
    • useRoute
    • useRouter
    • useState
  • Components
    • <NuxtPage>
    • <NuxtLayout>
    • <NuxtLink>
    • <NuxtErrorBoundary>
  • Utils
    • $fetch
    • abortNavigation
    • addRouteMiddleware
    • clearError
    • defineNuxtComponent
    • defineNuxtRouteMiddleware
    • definePageMeta
    • navigateTo
    • refreshNuxtData
    • throwError
  • Advanced
    • Lifecycle Hooks
    • Kit Utilities
  • Commands
    • nuxi add
    • nuxi analyze
    • nuxi build
    • nuxi dev
    • nuxi generate
    • nuxi info
    • nuxi init
    • nuxi preview
    • nuxi typecheck
    • nuxi upgrade
  • Configuration
    • Nuxt Config

useState

useState<T>(key: string, init?: () => T | Ref<T>): Ref<T>
  • key: A unique key ensuring that data fetching is properly de-duplicated across requests
  • init: A function that provides initial value for the state when not initiated. This function can also return a Ref.
  • T: (typescript only) Specify the type of state
👉
Read more in Guide > Features > State Management.
Edit this page on GitHub Updated at Wed, May 25, 2022

Composables useRouter
Components <NuxtPage>
Twitter GitHub

Nuxt 2 documentation