Component and hook for handling window and document object in iframe or ssr environment
npm install @chakra-ui/react-envReact component and hook for handling window and document object in iframe or
ssr environment
> This is an internal utility, not intended for public usage.
``sh`
yarn add @chakra-ui/react-envor
npm i @chakra-ui/react-env
To get it working, you need to wrap your app in EnvironmentProvider and calluseEnvironment
the hook anywhere in your app to get access to the correctwindow and document.
`jsx
import { EnvironmentProvider } from "@chakra-ui/react-env"
// in your App
const App = ({ children }) => {
return
}
// read the environment
const WindowSize = () => {
const { window } = useEnvironment()
return (
{JSON.stringify({
w: window.innerWidth,
h: window.innerHeight,
})}
If you wrap specific aspects of your app within an
iframe, you'll need to wrap
the content in the iframe in EnvironmentProvider to provide the correct
window and document to its content.`jsx
// in your app
const EmbeddedIFrame = () => {
return (
)
}
``Yes please! See the
contributing guidelines
for details.
This project is licensed under the terms of the
MIT license.