UNPKG

@gsretail.com/gui-core

Version:

A skeleton to create your own React component library using Rollup, TypeScript, Sass and Storybook

2 lines (1 loc) 1.06 kB
import*as e from"react";function t({controlled:t,default:o,name:n,state:r="value"}){const{current:s}=e.useRef(void 0!==t),[i,l]=e.useState(o),c=s?t:i;if("production"!==process.env.NODE_ENV){e.useEffect((()=>{s!==(void 0!==t)&&console.error([`MUI: A component is changing the ${s?"":"un"}controlled ${r} state of ${n} to be ${s?"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("\n"))}),[r,n,t]);const{current:i}=e.useRef(o);e.useEffect((()=>{s||i===o||console.error([`MUI: A component is changing the default ${r} state of an uncontrolled ${n} after being initialized. To suppress this warning opt to use a controlled ${n}.`].join("\n"))}),[JSON.stringify(o)])}return[c,e.useCallback((e=>{s||l(e)}),[])]}export{t as default};