You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

27 line
873 B

  1. import React from 'react';
  2. var unsafeLifecyclesPolyfill = function unsafeLifecyclesPolyfill(Component) {
  3. var prototype = Component.prototype;
  4. if (!prototype || !prototype.isReactComponent) {
  5. throw new Error('Can only polyfill class components');
  6. } // only handle componentWillReceiveProps
  7. if (typeof prototype.componentWillReceiveProps !== 'function') {
  8. return Component;
  9. } // In React 16.9, React.Profiler was introduced together with UNSAFE_componentWillReceiveProps
  10. // https://reactjs.org/blog/2019/08/08/react-v16.9.0.html#performance-measurements-with-reactprofiler
  11. if (!React.Profiler) {
  12. return Component;
  13. } // Here polyfill get started
  14. prototype.UNSAFE_componentWillReceiveProps = prototype.componentWillReceiveProps;
  15. delete prototype.componentWillReceiveProps;
  16. return Component;
  17. };
  18. export default unsafeLifecyclesPolyfill;