mirror of
https://github.com/zhigang1992/react.git
synced 2026-02-10 17:13:54 +08:00
21 lines
345 B
TypeScript
21 lines
345 B
TypeScript
|
|
const isBrowser = (): boolean => {
|
|
return Boolean(typeof window !== 'undefined' &&
|
|
window.document &&
|
|
window.document.createElement)
|
|
}
|
|
|
|
export type SSRState = {
|
|
isBrowser: boolean
|
|
isServer: boolean
|
|
}
|
|
|
|
const useSSR = (): SSRState => {
|
|
return {
|
|
isBrowser: isBrowser(),
|
|
isServer: !isBrowser(),
|
|
}
|
|
}
|
|
|
|
export default useSSR
|