@guruhotel/aura-hooks
Version:
🪝 Hooks library designed by the Guruhotel team for Aura UI
1 lines • 535 B
JavaScript
import{useRef as r,useEffect as t}from"react";import e from"./use-unmount";import n from"./deps-are-same";import{getTargetElement as u}from"./dom-target";export default(c,o,m)=>{const a=r(!1),i=r([]),l=r([]),p=r();t((()=>{const r=(Array.isArray(m)?m:[m]).map((r=>u(r)));if(!a.current)return a.current=!0,i.current=r,l.current=o,void(p.current=c());r.length===i.current.length&&n(r,i.current)&&n(o,l.current)||(null==p.current||p.current(),i.current=r,l.current=o,p.current=c())})),e((()=>{null==p.current||p.current(),a.current=!1}))};