UNPKG

1.13 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4Object.defineProperty(exports, "__esModule", {
5 value: true
6});
7exports.default = void 0;
8var _react = _interopRequireDefault(require("react"));
9var unsafeLifecyclesPolyfill = function unsafeLifecyclesPolyfill(Component) {
10 var prototype = Component.prototype;
11 if (!prototype || !prototype.isReactComponent) {
12 throw new Error('Can only polyfill class components');
13 }
14
15 // only handle componentWillReceiveProps
16 if (typeof prototype.componentWillReceiveProps !== 'function') {
17 return Component;
18 }
19
20 // In React 16.9, React.Profiler was introduced together with UNSAFE_componentWillReceiveProps
21 // https://reactjs.org/blog/2019/08/08/react-v16.9.0.html#performance-measurements-with-reactprofiler
22 if (!_react.default.Profiler) {
23 return Component;
24 }
25
26 // Here polyfill get started
27 prototype.UNSAFE_componentWillReceiveProps = prototype.componentWillReceiveProps;
28 delete prototype.componentWillReceiveProps;
29 return Component;
30};
31var _default = exports.default = unsafeLifecyclesPolyfill;
\No newline at end of file