UNPKG

zarm

Version:

基于 React 的移动端UI库

32 lines (30 loc) 1.7 kB
import { useEffect } from 'react'; /** * 自定义 Hook,用于在非生产环境下对废弃的 props 提示警告。 * @param {string} componentName - 发生类型变更的组件名称。 * @param {string} oldProp - 废弃的 prop 名称。 * @param {string} newProp - 新的 prop 名称。 */ export var useDeprecationWarning = function useDeprecationWarning(componentName, oldProp, newProp) { 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' 等)。 */ export var useTypeChangeWarning = function useTypeChangeWarning(condition, componentName, propName, propType, expectedType) { 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]); };