@cgi-learning-hub/ui
Version:
@cgi-learning-hub/ui is an open-source React component library that implements UI for HUB's features
32 lines (31 loc) • 1.27 kB
JavaScript
import * as t from "react";
function f(c) {
const {
controlled: n,
default: r,
name: o,
state: l = "value"
} = c, {
current: e
} = t.useRef(n !== void 0), [i, u] = t.useState(r), a = e ? n : i;
if (process.env.NODE_ENV !== "production") {
t.useEffect(() => {
e !== (n !== void 0) && console.error([`MUI: A component is changing the ${e ? "" : "un"}controlled ${l} state of ${o} to be ${e ? "un" : ""}controlled.`, "Elements should not switch from uncontrolled to controlled (or vice versa).", `Decide between using a controlled or uncontrolled ${o} 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(`
`));
}, [l, o, n]);
const {
current: s
} = t.useRef(r);
t.useEffect(() => {
!e && !Object.is(s, r) && console.error([`MUI: A component is changing the default ${l} state of an uncontrolled ${o} after being initialized. To suppress this warning opt to use a controlled ${o}.`].join(`
`));
}, [JSON.stringify(r)]);
}
const d = t.useCallback((s) => {
e || u(s);
}, []);
return [a, d];
}
export {
f as u
};