UNPKG

react-hooks-global-states

Version:

This is a package to easily handling global-state across your react-components using hooks.

1 lines 2.49 kB
var t;t=t=>(()=>{"use strict";var e={155:e=>{e.exports=t},163:(t,e,r)=>{function n(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,a,u,l=[],i=!0,c=!1;try{if(a=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;i=!1}else for(;!(i=(n=a.call(r)).done)&&(l.push(n.value),l.length!==e);i=!0);}catch(t){c=!0,o=t}finally{try{if(!i&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(c)throw o}}return l}}(t,e)||o(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(t,e){if(t){if("string"==typeof t)return a(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?a(t,e):void 0}}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}Object.defineProperty(e,"__esModule",{value:!0}),e.useStableState=void 0;var u=r(155);e.useStableState=function(t,e,r){var l,i,c=n((0,u.useState)({}),2)[1],f=(0,u.useCallback)((function(){c({})}),[]),s=(0,u.useRef)({builder:t,stateRef:null,fallback:r?{current:r}:void 0,isMounted:!1});s.current.builder=t,(0,u.useEffect)((function(){var t=n((0,s.current.builder)(),2),e=t[0],r=t[1];if(s.current.stateRef={current:e},f(),s.current.isMounted)return function(){null==r||r()};s.current.isMounted=!0}),[f].concat(function(t){if(Array.isArray(t))return a(t)}(i=e)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(i)||o(i)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()));var d=s.current,b=d.stateRef,y=d.fallback;return null!==(l=null!=b?b:y)&&void 0!==l?l:null},e.default=e.useStableState}},r={};return function t(n){var o=r[n];if(void 0!==o)return o.exports;var a=r[n]={exports:{}};return e[n](a,a.exports,t),a.exports}(163)})(),"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports["react-hooks-global-states"]=t(require("react")):this["react-hooks-global-states"]=t(this.react);