@mesmotronic/react-observable-div
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

ObservableDiv for React

This library provides a React component that creates a <div> element for embedding non-React things into, that dispatches events when it's mounted, unmounted or resized.

<ObservableDiv
  onMount={(domElement) => console.log("Mounted", domElement)}
  onUnmount={() => console.log("Unmounted")}
  onResize={({ width, height }) =>
    console.log(`Resized to ${width} x ${height}`)
  }
>
  {/* You can optionally put content here */}
</ObservableDiv>

This component provides the ideal host for things like a Three.js canvas, for example.

Strict mode

Please keep in mind that React's <StrictMode> may cause this component to dispatch the mount event twice in development. This is a know issue with <StrictMode> that affects all components and should be managed appropriately.

Package Sidebar

Install

npm i @mesmotronic/react-observable-div

Weekly Downloads

18

Version

1.0.4

License

BSD-3-Clause

Unpacked Size

6.05 kB

Total Files

6

Last publish

Collaborators

  • neilrackett