required-react-context
Version:
A simple React Context wrapper that throws an error if it is used without being provided
2 lines • 1.08 kB
JavaScript
var u=Object.create;var n=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var l=(e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})},N=(e,t,r,m)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of c(t))!f.call(e,o)&&o!==r&&n(e,o,{get:()=>t[o],enumerable:!(m=x(t,o))||m.enumerable});return e};var T=(e,t,r)=>(r=e!=null?u(C(e)):{},N(t||!e||!e.__esModule?n(r,"default",{value:e,enumerable:!0}):r,e)),y=e=>N(n({},"__esModule",{value:!0}),e);var h={};l(h,{use:()=>U});module.exports=y(h);var d=require("react");var i=Symbol.for("required-react-context/unset-value");function a(e,t){if(!e)throw new Error(t)}var s=T(require("react"),1);var p=(e,t)=>`${e}: context value is not set. Use ${t} to set the value.`;function v(e){return e.providerName??`${e.displayName??"Unknown"}.Provider`}function U(e){let t=(0,d.use)(e);return a(t!==i,"then"in e?"thenable returned UNSET_VALUE":p("use",v(e))),t}0&&(module.exports={use});
//# sourceMappingURL=canary.cjs.map
;