2020-02-18 13:26:15 -05:00
|
|
|
import { inject } from '../apiInject'
|
|
|
|
import { warn } from '../warning'
|
|
|
|
|
|
|
|
export const ssrContextKey = Symbol(__DEV__ ? `ssrContext` : ``)
|
|
|
|
|
|
|
|
export const useSSRContext = <T = Record<string, any>>() => {
|
|
|
|
if (!__GLOBAL__) {
|
|
|
|
const ctx = inject<T>(ssrContextKey)
|
|
|
|
if (!ctx) {
|
|
|
|
warn(
|
|
|
|
`Server rendering context not provided. Make sure to only call ` +
|
2021-01-18 14:51:41 -05:00
|
|
|
`useSSRContext() conditionally in the server build.`
|
2020-02-18 13:26:15 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
return ctx
|
|
|
|
} else if (__DEV__) {
|
2021-01-18 14:51:41 -05:00
|
|
|
warn(`useSSRContext() is not supported in the global build.`)
|
2020-02-18 13:26:15 -05:00
|
|
|
}
|
|
|
|
}
|