mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-16 10:54:49 +00:00
13 lines
359 B
TypeScript
13 lines
359 B
TypeScript
import type { Ref } from 'vue'
|
|
import { useNuxtApp } from '#app'
|
|
|
|
/**
|
|
* Create a global reactive ref that will be hydrated but not shared across ssr requests
|
|
*
|
|
* @param key a unique key to identify the data in the Nuxt payload
|
|
*/
|
|
export const useState = <T> (key: string): Ref<T> => {
|
|
const nuxt = useNuxtApp()
|
|
return toRef(nuxt.payload.state, key)
|
|
}
|