パッケージの詳細

@teste-ui/react-env

teste-ui11MIT2.0.4

Component and hook for handling window and document object in iframe or ssr environment

dom, environment context, ssr, iframe

readme

@teste-ui/react-env

React component and hook for handling window and document object in iframe or ssr environment

This is an internal utility, not intended for public usage.

Installation

yarn add @teste-ui/react-env
# or
npm i @teste-ui/react-env

Usage

To get it working, you need to wrap your app in EnvironmentProvider and call the useEnvironment hook anywhere in your app to get access to the correct window and document.

import { EnvironmentProvider } from "@teste-ui/react-env"

// in your App
const App = ({ children }) => {
  return <EnvironmentProvider>{children}</EnvironmentProvider>
}

// read the environment
const WindowSize = () => {
  const { window } = useEnvironment()
  return (
    <pre>
      {JSON.stringify({
        w: window.innerWidth,
        h: window.innerHeight,
      })}
    </pre>
  )
}

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.

// in your app
const EmbeddedIFrame = () => {
  return (
    <Frame>
      <EnvironmentProvider>
        <WindowSize />
      </EnvironmentProvider>
    </Frame>
  )
}

Contribution

Yes please! See the contributing guidelines for details.

Licence

This project is licensed under the terms of the MIT license.

更新履歴

@teste-ui/react-env

2.0.4

Patch Changes

2.0.3

Patch Changes

2.0.2

Patch Changes

2.0.1

Patch Changes

  • Updated dependencies [f77e3c98f]:
    • @teste-ui/utils@2.0.1

2.0.0

Major Changes

Patch Changes

  • #5906 ad84d8efc Thanks @segunadebayo! - Fix issue where EnviromentProvider causes suspense boundary to throw hydration errors.

    Always render the env getter element to ensure consistent behavior in all environments.

  • Updated dependencies [c390af485, ed692c0ae, 41b3119f5]:

    • @teste-ui/utils@2.0.0

2.0.0-next.2

Major Changes

Patch Changes

  • Updated dependencies [ed692c0ae]:
    • @teste-ui/utils@2.0.0-next.2

2.0.0-next.1

Major Changes

Patch Changes

  • #5906 ad84d8efc Thanks @segunadebayo! - Fix issue where EnviromentProvider causes suspense boundary to throw hydration errors.

    Always render the env getter element to ensure consistent behavior in all environments.

  • Updated dependencies [41b3119f5]:

    • @teste-ui/utils@2.0.0-next.1

2.0.0-next.0

Major Changes

Patch Changes

  • Updated dependencies [c390af485]:
    • @teste-ui/utils@2.0.0-next.0

1.1.6

Patch Changes

  • e1fe48cbe Thanks @TimKolberger! - Bumped patch version for every package to fix release process. Root cause was a bug in our CI configuration.
  • Updated dependencies [e1fe48cbe]:
    • @teste-ui/utils@1.10.4

1.1.5

Patch Changes

  • Updated dependencies [a870e6b94]:
    • @teste-ui/utils@1.10.3

1.1.4

Patch Changes

1.1.3

Patch Changes

  • Updated dependencies [24b4333d0]:
    • @teste-ui/utils@1.10.1

1.1.2

Patch Changes

  • Updated dependencies [1537a725f]:
    • @teste-ui/utils@1.10.0

1.1.1

Patch Changes

  • #5075 b28142946 Thanks @cschroeter! - Update babel config to transpile soruces for older browsers. This fixes issues with CRA and Storybook.
  • Updated dependencies [b28142946]:
    • @teste-ui/utils@1.9.1

1.1.0

Minor Changes

  • #4991 6095eaf9a Thanks @segunadebayo! - Update build system we use from a custom babel cli setup to preconstruct.

    The previous build system transpiles the code in src directory to dist/esm and dist/cjs keeping the same file structure. The new build system merges all files in src and transpiles to a single esm and cjs file.

    Potential Breaking Change: The side effect of this is that, if you imported any function, component or hook using the undocumented approach like import { useOutsideClick } from "@teste-ui/hooks/dist/use-outside-click", you'll notice that the this doesn't work anymore.

    Here's how to resolve it:

    ```jsx live=false // Won't work 🎇 import { useOutsideClick } from "@teste-ui/hooks/dist/use-outside-click"

    // Works ✅ import { useOutsideClick } from "@teste-ui/hooks" ```

    If this affected your project, we recommend that you import hooks, functions or components the way it's shown in the documentation. This will help keep your project future-proof.

Patch Changes

  • Updated dependencies [6095eaf9a]:
    • @teste-ui/utils@1.9.0

1.0.8

Patch Changes

  • Updated dependencies [cd0893c56]:
    • @teste-ui/utils@1.8.4

1.0.7

Patch Changes

1.0.6

Patch Changes

1.0.5

Patch Changes

  • Updated dependencies [4a1e4d93b]:
    • @teste-ui/utils@1.8.1

1.0.4

Patch Changes

1.0.3

Patch Changes

  • Updated dependencies [e9ac4cc76]:
    • @teste-ui/utils@1.7.0

1.0.2

Patch Changes

1.0.1

Patch Changes

  • 19421fa94 Thanks @segunadebayo! - - Fix issue where window could be null
    • Skip logic when environment prop is passed