Skip to content

Commit 14a20c8

Browse files
committed
Merge branch 'patch-4' of https://github.com/jamiehodge/redux into jamiehodge-patch-4
2 parents 6c3a633 + 9b718f4 commit 14a20c8

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/components/createConnector.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default function createConnector(React) {
4040

4141
this.handleChange = this.handleChange.bind(this);
4242
this.unsubscribe = context.redux.subscribe(this.handleChange);
43-
this.handleChange();
43+
this.state = this.selectState({ context, props });
4444
}
4545

4646
componentWillReceiveProps(nextProps) {
@@ -55,14 +55,13 @@ export default function createConnector(React) {
5555
}
5656

5757
handleChange() {
58-
const state = this.context.redux.getState();
59-
const slice = this.props.select(state);
58+
this.setState(this.selectState());
59+
}
6060

61-
if (this.state) {
62-
this.setState({ slice });
63-
} else {
64-
this.state = { slice };
65-
}
61+
selectState({ context, props } = this) {
62+
const state = context.redux.getState();
63+
const slice = props.select(state);
64+
return { slice };
6665
}
6766

6867
render() {

0 commit comments

Comments
 (0)