react-attractor
Version:
React library to map DOM elements to React components
2 lines (1 loc) • 937 B
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react/jsx-runtime"),r=require("react"),h=r.createContext(null),d=({children:e})=>{const n=r.useRef(new WeakMap),u=r.useCallback((t,s)=>{t&&n.current.set(t,s)},[]),a=r.useCallback(t=>n.current.get(t),[]),o={registerTether:u,getTether:a};return i.jsx(h.Provider,{value:o,children:e})},l=()=>{const e=r.useContext(h);if(!e)throw new Error("useTetherContext must be used within a TetherProvider");return e};function x(e){return e!==null&&typeof e=="object"&&e!==null&&"$$typeof"in e}function C(e){const n=u=>{const{tetherMetadata:a,...o}=u,{registerTether:t}=l(),s={props:o,metadata:a},f=r.useCallback(c=>{c&&t(c,s)},[t,s]),T={...o,ref:f};return i.jsx(e,{...T})};return n.displayName=`withTether(${e.displayName||e.name||"Component"})`,n}exports.TetherProvider=d;exports.isForwardRefComponent=x;exports.useTetherContext=l;exports.withTether=C;