Skip to content

Commit 4d70a7e

Browse files
authored
added crude implementation of react redux connect hoc
1 parent 7bcdad3 commit 4d70a7e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

react-redux-connect.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// crude implementation of react redux connect using hoc
2+
3+
import React,{Component} from "react";
4+
5+
const connect = (ChildComponent, mapStateToProps, mapDispatchToProps) => {
6+
7+
return class Container extends Component{
8+
9+
render(){
10+
const state = this.context.store.getState();
11+
const dispatch = this.context.store.dispatch;
12+
const stateToProps = mapStateToProps(state);
13+
const dispatchToProps = mapDispatchToProps(dispatch);
14+
return <ChildComponent {...this.props} {...stateToProps} {...dispatchToProps} />
15+
}
16+
}
17+
18+
};

0 commit comments

Comments
 (0)