@@ -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,7 @@ export default function createConnect(React) {
161
173
}
162
174
163
175
getWrappedInstance ( ) {
164
- return this . refs . wrappedInstance ;
176
+ return this . refs . wrappedInstance . refs . wrappedInstance ;
165
177
}
166
178
167
179
computeNextState ( ) {
@@ -176,9 +188,15 @@ export default function createConnect(React) {
176
188
177
189
const finalProps = this . computeNextState ( ) ;
178
190
191
+ if ( ! pure ) {
192
+ return < WrappedComponent { ...finalProps } /> ;
193
+ }
194
+
179
195
return (
180
- < WrappedComponent ref = 'wrappedInstance'
181
- { ...finalProps } />
196
+ < PureWrap
197
+ ref = 'wrappedInstance'
198
+ component = { WrappedComponent }
199
+ passProps = { finalProps } />
182
200
) ;
183
201
}
184
202
}
0 commit comments