UNPKG

@guruhotel/aura-hooks

Version:

🪝 Hooks library designed by the Guruhotel team for Aura UI

1 lines 640 B
exports.__esModule=!0,exports.useMediaQuery=function(t,n,{getInitialValueInEffect:r}={getInitialValueInEffect:!0}){const[i,a]=(0,e.useState)(!r&&function(e,t){if("boolean"==typeof t)return t;if("undefined"!=typeof window&&"matchMedia"in window)return window.matchMedia(e).matches;return!1}(t,n)),u=(0,e.useRef)();return(0,e.useEffect)((()=>{if("matchMedia"in window)return u.current=window.matchMedia(t),a(u.current.matches),function(e,t){try{return e.addEventListener("change",t),()=>e.removeEventListener("change",t)}catch(n){return e.addListener(t),()=>e.removeListener(t)}}(u.current,(e=>a(e.matches)))}),[t]),i};var e=require("react");