@cgi-learning-hub/ui
Version:
@cgi-learning-hub/ui is an open-source React component library that implements UI for HUB's features
4 lines (3 loc) • 1.38 kB
JavaScript
const d=require("react");function p(o){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const e in o)if(e!=="default"){const n=Object.getOwnPropertyDescriptor(o,e);Object.defineProperty(t,e,n.get?n:{enumerable:!0,get:()=>o[e]})}}return t.default=o,Object.freeze(t)}const l=p(d);function m(o){const{controlled:t,default:e,name:n,state:c="value"}=o,{current:r}=l.useRef(t!==void 0),[i,u]=l.useState(e),a=r?t:i;if(process.env.NODE_ENV!=="production"){l.useEffect(()=>{r!==(t!==void 0)&&console.error([`MUI: A component is changing the ${r?"":"un"}controlled ${c} state of ${n} to be ${r?"un":""}controlled.`,"Elements should not switch from uncontrolled to controlled (or vice versa).",`Decide between using a controlled or uncontrolled ${n} element for the lifetime of the component.`,"The nature of the state is determined during the first render. It's considered controlled if the value is not `undefined`.","More info: https://fb.me/react-controlled-components"].join(`
`))},[c,n,t]);const{current:s}=l.useRef(e);l.useEffect(()=>{!r&&!Object.is(s,e)&&console.error([`MUI: A component is changing the default ${c} state of an uncontrolled ${n} after being initialized. To suppress this warning opt to use a controlled ${n}.`].join(`
`))},[JSON.stringify(e)])}const f=l.useCallback(s=>{r||u(s)},[]);return[a,f]}exports.useControlled=m;
;