Created
March 9, 2014 22:10
-
-
Save liammclennan/9455524 to your computer and use it in GitHub Desktop.
React mixin that warns if a propTypes key is missing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define('validation', [], function() { | |
return { | |
allPropsSpecifiedMixing: { | |
componentDidMount: function() { | |
var unspecifiedPropKeys = _.difference( | |
_.keys(this.props), | |
_.keys(this.type.propTypes || {}).concat('ref')); | |
if (unspecifiedPropKeys.length) { | |
console.warn('Component ' + | |
(this.type.displayName || '?') + | |
' missing propType values for: ' + | |
JSON.stringify(unspecifiedPropKeys)); | |
} | |
} | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment