Use better names for components wrapped into HOC

Currently the `displayName` of the component wrapped into HOC looks like `Constructor`, which isn't very descriptive.
This PR introduces a better `displayName` for such components: `Formsy(ComponentName)`
This commit is contained in:
Vladimir Guguiev 2016-06-11 13:21:44 +02:00 committed by GitHub
parent 89a2d4287b
commit 9e923dd0dc
1 changed files with 9 additions and 0 deletions

View File

@ -2,6 +2,7 @@ var React = global.React || require('react');
var Mixin = require('./Mixin.js');
module.exports = function (Component) {
return React.createClass({
displayName: 'Formsy(' + getDisplayName(Component) + ')',
mixins: [Mixin],
render: function () {
return React.createElement(Component, {
@ -25,3 +26,11 @@ module.exports = function (Component) {
}
});
};
function getDisplayName(Component) {
return (
Component.displayName ||
Component.name ||
(typeof Component === 'string' ? Component : 'Component')
);
}