Skip to content
This repository was archived by the owner on Apr 5, 2025. It is now read-only.

Commit 8ea1cf4

Browse files
tony99nyrjimfb
authored andcommitted
Update shallowCompare to accept nextContext (facebook#6661)
* Update shallowCompare to accept nextContext Across our application we are using immutable objects as properties and thus using shallowCompare for all our {{shouldComponentUpdate}}. Because of this children with contextTypes don't get updates when the context on the parent changes. Adding an additional comparison for context (when it is provided) fixes this problem. * Remove the undefined check * Add nextContext
1 parent 7f08961 commit 8ea1cf4

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/addons/ReactComponentWithPureRenderMixin.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ var shallowCompare = require('shallowCompare');
4040
* See https://facebook.github.io/react/docs/pure-render-mixin.html
4141
*/
4242
var ReactComponentWithPureRenderMixin = {
43-
shouldComponentUpdate: function(nextProps, nextState) {
44-
return shallowCompare(this, nextProps, nextState);
43+
shouldComponentUpdate: function(nextProps, nextState, nextContext) {
44+
return shallowCompare(this, nextProps, nextState, nextContext);
4545
},
4646
};
4747

src/addons/shallowCompare.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ var shallowEqual = require('shallowEqual');
1818
* See ReactComponentWithPureRenderMixin
1919
* See also https://facebook.github.io/react/docs/shallow-compare.html
2020
*/
21-
function shallowCompare(instance, nextProps, nextState) {
21+
function shallowCompare(instance, nextProps, nextState, nextContext) {
2222
return (
2323
!shallowEqual(instance.props, nextProps) ||
24-
!shallowEqual(instance.state, nextState)
24+
!shallowEqual(instance.state, nextState) ||
25+
!shallowEqual(instance.context, nextContext)
2526
);
2627
}
2728

0 commit comments

Comments
 (0)