Skip to content

Commit 726c730

Browse files
committed
Future proof cwp, remove unused internal utils
Adds a version check to cwp so that it only wraps `child.type` in a mock factory for version 0.12, as it would break in 0.13, where `react.createElement === require("react/lib/ReactElement").createElement` will be `true`
1 parent 72bb590 commit 726c730

3 files changed

Lines changed: 9 additions & 99 deletions

File tree

src/utils/ReactContext.js

Lines changed: 0 additions & 63 deletions
This file was deleted.

src/utils/ReactCurrentOwner.js

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/utils/cloneWithProps.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,17 @@ function cloneWithProps(child, props) {
127127
newProps.children = child.props.children;
128128
}
129129

130+
if (React.version.substr(0, 4) === '0.12'){
131+
var mockLegacyFactory = function(){};
132+
mockLegacyFactory.isReactLegacyFactory = true;
133+
mockLegacyFactory.type = child.type;
134+
135+
return React.createElement(mockLegacyFactory, newProps);
136+
}
137+
130138
// The current API doesn't retain _owner and _context, which is why this
131139
// doesn't use ReactElement.cloneAndReplaceProps.
132-
var mockLegacyFactory = function(){};
133-
mockLegacyFactory.isReactLegacyFactory = true;
134-
mockLegacyFactory.type = child.type;
135-
return React.createElement(mockLegacyFactory, newProps);
140+
return React.createElement(child.type, newProps);
136141
}
137142

138143
module.exports = cloneWithProps;

0 commit comments

Comments
 (0)