UNPKG

@nethesis/phone-island

Version:
3 lines (2 loc) 2.27 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("./useReduxContext.js"),r=require("../components/Context.js");let n=require("../utils/useSyncExternalStore.js").notInitialized;const o=(e,t)=>e===t;function s(){let s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:r.ReactReduxContext;const a=s===r.ReactReduxContext?t.useReduxContext:t.createReduxContextHook(s);return function(t){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{equalityFn:s=o,stabilityCheck:c,noopCheck:u}="function"==typeof r?{equalityFn:r}:r;if("production"!==process.env.NODE_ENV){if(!t)throw new Error("You must pass a selector to useSelector");if("function"!=typeof t)throw new Error("You must pass a function as a selector to useSelector");if("function"!=typeof s)throw new Error("You must pass a function as an equality function to useSelector")}const{store:i,subscription:l,getServerState:d,stabilityCheck:h,noopCheck:f}=a(),w=e.useRef(!0),p=e.useCallback({[t.name](e){const r=t(e);if("production"!==process.env.NODE_ENV){const n=void 0===c?h:c;if("always"===n||"once"===n&&w.current){const n=t(e);if(!s(r,n)){let o;try{throw new Error}catch(e){({stack:o}=e)}console.warn("Selector "+(t.name||"unknown")+" returned a different result when called with the same parameters. This can lead to unnecessary rerenders.\nSelectors that return a new reference (such as an object or an array) should be memoized: https://redux.js.org/usage/deriving-data-selectors#optimizing-selectors-with-memoization",{state:e,selected:r,selected2:n,stack:o})}}const o=void 0===u?f:u;if(("always"===o||"once"===o&&w.current)&&r===e){let e;try{throw new Error}catch(t){({stack:e}=t)}console.warn("Selector "+(t.name||"unknown")+" returned the root state when called. This can lead to unnecessary rerenders.\nSelectors that return the entire state are almost certainly a mistake, as they will cause a rerender whenever *anything* in state changes.",{stack:e})}w.current&&(w.current=!1)}return r}}[t.name],[t,h,c]),y=n(l.addNestedSub,i.getState,d||i.getState,p,s);return e.useDebugValue(y),y}}const a=s();exports.createSelectorHook=s,exports.initializeUseSelector=e=>{n=e},exports.useSelector=a; //# sourceMappingURL=useSelector.js.map