Skip to content

Commit 13aae40

Browse files
committed
dont update state if memoized
1 parent 2bbc80d commit 13aae40

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/Memoizer.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ const createMemoizer = (memoizationFunction) => {
2121
const { calculateResult } = state;
2222
const { children, compute, pure, ...rest } = props;
2323
const result = state.calculateResult(rest);
24-
return {
25-
calculateResult,
26-
result,
27-
};
24+
if(result !== state.result) {
25+
return {
26+
result
27+
};
28+
}
29+
return null;
2830
}
2931

3032
state = {

src/Waterflow.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export class MemoizedFlow extends React.Component {
1212
/* eslint-enable */
1313
flow: PropTypes.arrayOf(PropTypes.func).isRequired,
1414
children: PropTypes.func.isRequired,
15+
16+
pure: PropTypes.bool
1517
};
1618

1719
static getDerivedStateFromProps(props, state) {
@@ -25,7 +27,7 @@ export class MemoizedFlow extends React.Component {
2527
};
2628

2729
shouldComponentUpdate(nextProps, nextState) {
28-
return nextState.value !== this.state.value;
30+
return !this.props.pure || nextState.value !== this.state.value;
2931
}
3032

3133
render() {

0 commit comments

Comments
 (0)