manifold/web/hooks/use-is-iframe.ts
2022-09-06 22:43:28 -05:00

16 lines
325 B
TypeScript

import { useEffect, useState } from 'react'
export function inIframe() {
try {
return window.self !== window.top
} catch (e) {
return true
}
}
export function useIsIframe() {
const [is, setIs] = useState(false)
useEffect(() => setIs(inIframe()), []) // useEffect so this happens client side
return is
}