No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

unsafeLifecyclesPolyfill.js 873 B

hace 3 años
123456789101112131415161718192021222324252627
  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;