-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathwarnDeprecations.ts
More file actions
26 lines (25 loc) · 1003 Bytes
/
warnDeprecations.ts
File metadata and controls
26 lines (25 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { warn } from './warn';
import type { ISettingsMap } from './warn';
/**
* Warns when a deprecated props are being used.
*
* @public
* @param componentName - The name of the component being used.
* @param props - The props passed into the component.
* @param deprecationMap - The map of deprecations, where key is the prop name and the value is
* either null or a replacement prop name.
*/
export function warnDeprecations<P extends {}>(componentName: string, props: P, deprecationMap: ISettingsMap<P>): void {
if (process.env.NODE_ENV !== 'production') {
for (const propName in deprecationMap) {
if (props && propName in props) {
let deprecationMessage = `${componentName} property '${propName}' was used but has been deprecated.`;
const replacementPropName = deprecationMap[propName];
if (replacementPropName) {
deprecationMessage += ` Use '${replacementPropName}' instead.`;
}
warn(deprecationMessage);
}
}
}
}