antd
Version:
An enterprise-class UI design language and React components implementation
56 lines (55 loc) • 2.02 kB
JavaScript
;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.devUseWarning = exports.default = exports.WarningContext = void 0;
exports.noop = noop;
Object.defineProperty(exports, "resetWarned", {
enumerable: true,
get: function () {
return _warning.resetWarned;
}
});
var React = _interopRequireWildcard(require("react"));
var _warning = _interopRequireWildcard(require("rc-util/lib/warning"));
function noop() {}
// eslint-disable-next-line import/no-mutable-exports
let warning = noop;
if (process.env.NODE_ENV !== 'production') {
warning = (valid, component, message) => {
(0, _warning.default)(valid, `[antd: ${component}] ${message}`);
// StrictMode will inject console which will not throw warning in React 17.
if (process.env.NODE_ENV === 'test') {
(0, _warning.resetWarned)();
}
};
}
const WarningContext = /*#__PURE__*/React.createContext({});
/**
* This is a hook but we not named as `useWarning`
* since this is only used in development.
* We should always wrap this in `if (process.env.NODE_ENV !== 'production')` condition
*/
exports.WarningContext = WarningContext;
const devUseWarning = process.env.NODE_ENV !== 'production' ? component => {
const {
deprecated
} = React.useContext(WarningContext);
const typeWarning = (valid, type, message) => {
if (deprecated !== false || type !== 'deprecated') {
process.env.NODE_ENV !== "production" ? warning(valid, component, message) : void 0;
}
};
typeWarning.deprecated = (valid, oldProp, newProp, message) => {
typeWarning(valid, 'deprecated', `\`${oldProp}\` is deprecated. Please use \`${newProp}\` instead.${message ? ` ${message}` : ''}`);
};
return typeWarning;
} : () => {
const noopWarning = () => {};
noopWarning.deprecated = noop;
return noopWarning;
};
exports.devUseWarning = devUseWarning;
var _default = warning;
exports.default = _default;