unsafeLifecyclesPolyfill.js 1.1 KB

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