c54d15fd93
* feat: authz frontend foundation + reworked errors * lint fixes * test fix * fixed noCache() util
18 lines
523 B
TypeScript
18 lines
523 B
TypeScript
/**
|
|
* Similar to nuxt's useState() except state is scoped to only the SSR request or only the client-side session.
|
|
* The state doesn't get serialized in SSR and thus won't be transferred to the client-side session
|
|
*/
|
|
export function useScopedState<T>(key: string | symbol, init: () => T) {
|
|
const nuxtApp = useNuxtApp()
|
|
|
|
if (!nuxtApp.__scopedStates) {
|
|
nuxtApp.__scopedStates = {}
|
|
}
|
|
|
|
if (!nuxtApp.__scopedStates[key]) {
|
|
nuxtApp.__scopedStates[key] = init()
|
|
}
|
|
|
|
return nuxtApp.__scopedStates[key] as T
|
|
}
|