UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

2 lines (1 loc) 601 B
import{useEffect as f,useState as m}from"react";import{uiState as t}from"../store";import{getRenderTargetFromRoot as u}from"./getRenderTargetFromRoot";export const useRenderTarget=()=>{const[l,i]=m(()=>u(t.rootElement));return f(()=>{if(typeof window>"u"||!t.rootElement)return;let o=!1,e=null;const n=()=>{const r=u(t.rootElement);return r&&!o?(i(s=>s!==r?r:s),!0):!1};if(n())return;const a=t.rootElement.firstElementChild?.shadowRoot??t.rootElement;return e=new MutationObserver(()=>{n()&&e&&e.disconnect()}),e.observe(a,{childList:!0,subtree:!0}),()=>{o=!0,e&&e.disconnect()}},[t.rootElement]),l};