11import React , { Component } from 'react' ;
22import PropTypes from 'prop-types' ;
3+ import polyfill from 'react-lifecycles-compat' ;
34
45import memoizeState from 'memoize-state' ;
56import memoizeOne from 'memoize-one' ;
67
7- const createMemoizer = memoizationFunction => (
8+ const createMemoizer = ( memoizationFunction ) => {
89 class Memoize extends Component {
910 static propTypes = {
1011 children : PropTypes . func . isRequired ,
@@ -35,10 +36,6 @@ const createMemoizer = memoizationFunction => (
3536 } ) ;
3637 }
3738
38- componentWillReceiveProps ( newProps ) {
39- this . setState ( Memoize . getDerivedStateFromProps ( newProps , this . state ) ) ;
40- }
41-
4239 shouldComponentUpdate ( nextProps , nextState ) {
4340 return ! nextProps . pure || nextState . changed ;
4441 }
@@ -47,7 +44,10 @@ const createMemoizer = memoizationFunction => (
4744 return this . props . children ( this . state . result ) ;
4845 }
4946 }
50- ) ;
47+
48+ polyfill ( Memoize ) ;
49+ return Memoize ;
50+ } ;
5151
5252export const MemoizeOne = createMemoizer ( memoizeOne ) ;
5353export const MemoizeState = createMemoizer ( memoizeState ) ;
@@ -74,6 +74,6 @@ MemoizeContext.defaultProps = {
7474} ;
7575
7676
77- const MemoizeDefault = typeof Proxy !== 'undefined' ? MemoizeState : MemoizeOne ;
77+ const MemoizeDefault = MemoizeState ;
7878
7979export default MemoizeDefault ;
0 commit comments