@@ -23,6 +23,18 @@ export default function createConnect(React) {
23
23
const { Component, PropTypes } = React ;
24
24
const storeShape = createStoreShape ( PropTypes ) ;
25
25
26
+ // Avoids rendering if the props did not change
27
+ class PureWrap extends Component {
28
+ shouldComponentUpdate ( nextProps ) {
29
+ return ! shallowEqual ( this . props . passProps , nextProps . passProps ) ;
30
+ }
31
+ render ( ) {
32
+ const PureWrappedComponent = this . props . component ;
33
+ return < PureWrappedComponent ref = 'wrappedInstance' { ...this . props . passProps } /> ;
34
+ }
35
+ }
36
+
37
+
26
38
return function connect ( mapStateToProps , mapDispatchToProps , mergeProps , options = { } ) {
27
39
const shouldSubscribe = Boolean ( mapStateToProps ) ;
28
40
const finalMapStateToProps = mapStateToProps || defaultMapStateToProps ;
@@ -161,7 +173,11 @@ export default function createConnect(React) {
161
173
}
162
174
163
175
getWrappedInstance ( ) {
164
- return this . refs . wrappedInstance ;
176
+ if ( pure ) {
177
+ return this . refs . wrappedInstance . refs . wrappedInstance ;
178
+ } else {
179
+ return this . refs . wrappedInstance ;
180
+ }
165
181
}
166
182
167
183
computeNextState ( ) {
@@ -176,9 +192,15 @@ export default function createConnect(React) {
176
192
177
193
const finalProps = this . computeNextState ( ) ;
178
194
195
+ if ( ! pure ) {
196
+ return < WrappedComponent { ...finalProps } /> ;
197
+ }
198
+
179
199
return (
180
- < WrappedComponent ref = 'wrappedInstance'
181
- { ...finalProps } />
200
+ < PureWrap
201
+ ref = 'wrappedInstance'
202
+ component = { WrappedComponent }
203
+ passProps = { finalProps } />
182
204
) ;
183
205
}
184
206
}
0 commit comments