Skip to content

Commit 5faa94d

Browse files
committed
feat(util): add warnOnce and deprecated fns
Add deprected util to mark prop-types as deprected Add warnOnce to display a message in the console, never the same message twice
1 parent 3585764 commit 5faa94d

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/utils.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,24 @@ export function omit(obj, omitKeys) {
167167
});
168168
return result;
169169
}
170+
171+
let warned = {};
172+
173+
export function warnOnce(message) {
174+
if (!warned[message]) {
175+
if (typeof console !== 'undefined') {
176+
console.error(message); // eslint-disable-line no-console
177+
}
178+
warned[message] = true;
179+
}
180+
}
181+
182+
export function deprecated(propType, explanation) {
183+
return function validate(props, propName, componentName, ...rest) {
184+
if (props[propName] !== null && typeof props[propName] !== 'undefined') {
185+
warnOnce(`"${propName}" property of "${componentName}" has been deprecated.\n${explanation}`);
186+
}
187+
188+
return propType(props, propName, componentName, ...rest);
189+
};
190+
}

0 commit comments

Comments
 (0)