0.1.23 • Published 10 months ago

react-ref-boundary v0.1.23

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

react-ref-boundary

React context for grouping react references by boundary in react dom, native and web. Ideal for group references for contains checks when using react portals.

Example 1

import { useRef as useReactRef, Fragment } from "react";
import { BoundaryProvider, useRef, useBoundary } from "react-ref-boundary";

function NonBoundaryComponent() {
  const ref = useReactRef < HTMLDivElement > null;
  return <div ref={ref} />;
}

function BoundaryComponent() {
  const ref = useBoundaryRef < HTMLDivElement > null;
  return <div ref={ref} />;
}

function BoundaryChecker() {
  const boundary = useBoundary();
  return (
    <button
      onClick={(event) => {
        if (
          !boundary.refs.some(
            (ref) => ref.current && ref.current.contains(event.target),
          )
        ) {
          // outside all of the references
        }
      }}
    />
  );
}

function BoundaryChecker({ getRefs }) {
  const boundary = useBoundary();
  getRefs(boundary.refs);
  return <Fragment />;
}

render(
  <BoundaryProvider>
    <BoundaryComponent />
    <NonBoundaryComponent />
    <BoundaryComponent />
    <BoundaryChecker />
  </BoundaryProvider>,
);

Documentation

API Docs

0.1.20

11 months ago

0.1.21

11 months ago

0.1.10

12 months ago

0.1.23

10 months ago

0.1.12

12 months ago

0.1.13

12 months ago

0.1.14

12 months ago

0.1.15

12 months ago

0.1.16

12 months ago

0.1.8

12 months ago

0.1.17

12 months ago

0.1.7

12 months ago

0.1.18

11 months ago

0.1.19

11 months ago

0.1.9

12 months ago

0.1.6

12 months ago

0.1.4

2 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

4 years ago