Skip to content

Commit 9757236

Browse files
committed
React 16.3 + react-lifecycles-compat
1 parent 1757df8 commit 9757236

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
Component memoization for React! Based on [Dan Abramov's tweet](https://twitter.com/dan_abramov/status/965378278461755392) :)
66
Could change the way you did `componentWillReceiveProps`, could remember how your React Tree grow, could make things better.
77

8+
> IE11+, React 15 and React 16.3 compatible.
9+
810
[![NPM](https://nodei.co/npm/react-memoize.png?downloads=true&stars=true)](https://nodei.co/npm/react-memoize/)
911

1012
```js

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"dependencies": {
6969
"memoize-one": "^3.0.1",
7070
"memoize-state": "^1.3.3",
71-
"prop-types": "15.5.10"
71+
"prop-types": "15.5.10",
72+
"react-lifecycles-compat": "^1.1.0"
7273
}
7374
}

src/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
3+
import polyfill from 'react-lifecycles-compat';
34

45
import memoizeState from 'memoize-state';
56
import 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

5252
export const MemoizeOne = createMemoizer(memoizeOne);
5353
export 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

7979
export default MemoizeDefault;

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6381,6 +6381,10 @@ react-inspector@^2.2.2:
63816381
babel-runtime "^6.26.0"
63826382
is-dom "^1.0.9"
63836383

6384+
react-lifecycles-compat@^1.1.0:
6385+
version "1.1.0"
6386+
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-1.1.0.tgz#6641d0709bd5505329b5c90322147ef2d343485c"
6387+
63846388
react-modal@^3.1.10:
63856389
version "3.2.1"
63866390
resolved "https://registry.yarnpkg.com/react-modal/-/react-modal-3.2.1.tgz#fa8f76aed55b67c22dcf1a1c15b05c8d11f18afe"

0 commit comments

Comments
 (0)