zarm
Version:
基于 React 的移动端UI库
44 lines (37 loc) • 1.97 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useTypeChangeWarning = exports.useDeprecationWarning = void 0;
var _react = require("react");
/**
* 自定义 Hook,用于在非生产环境下对废弃的 props 提示警告。
* @param {string} componentName - 发生类型变更的组件名称。
* @param {string} oldProp - 废弃的 prop 名称。
* @param {string} newProp - 新的 prop 名称。
*/
var useDeprecationWarning = function useDeprecationWarning(componentName, oldProp, newProp) {
(0, _react.useEffect)(function () {
if (process.env.NODE_ENV !== 'production' && oldProp !== undefined) {
console.warn("Warning: The prop \"".concat(oldProp, "\" will be deprecated. ") + "you can use \"".concat(newProp, "\" instead.") + "\n\nPlease update the following components: ".concat(componentName));
}
}, [componentName, oldProp, newProp]);
};
/**
* 自定义 Hook,用于在非生产环境下对类型变更的 props 提示警告。
* @param {string} componentName - 发生类型变更的组件名称。
* @param {string} propName - 发生类型变更的 prop 名称。
* @param {string} propType - 传入的 prop 类型。
* @param {string} expectedType - 预期的新类型(如 'object', 'number' 等)。
*/
exports.useDeprecationWarning = useDeprecationWarning;
var useTypeChangeWarning = function useTypeChangeWarning(condition, componentName, propName, propType, expectedType) {
(0, _react.useEffect)(function () {
if (process.env.NODE_ENV !== 'production') {
if (condition) {
console.warn("Warning: The prop \"".concat(propName, "\" is expected to be of type \"").concat(expectedType, "\", ") + "but received type \"".concat(propType, "\". ") + "\n\nPlease update the following components: ".concat(componentName));
}
}
}, [condition, componentName, propName, propType, expectedType]);
};
exports.useTypeChangeWarning = useTypeChangeWarning;
;