Skip to content

Instantly share code, notes, and snippets.

@vampaynani
Created March 9, 2018 19:51
Show Gist options
  • Save vampaynani/89d8cfcb03819a439a6b03c3c329eb2a to your computer and use it in GitHub Desktop.
Save vampaynani/89d8cfcb03819a439a6b03c3c329eb2a to your computer and use it in GitHub Desktop.
How does Redux Connect works
function connect(mapStateToProps){
const state = {
currentGuess: 0,
response: '',
guesses: []
};
return function(component){
newProps = Object.assign(
{},
component.props,
mapStateToProps(state),
{ dispatch: function(){} }
);
return Object.assign({}, component, {props: newProps});
}
}
var component = {
tag: 'div',
props: {},
setState: function(){}
}
const mapStateToProps = state => {
return {
guess: state.currentGuess,
guesses: state.guesses
};
};
console.log(connect(mapStateToProps)(component));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment