Created
March 9, 2018 19:51
-
-
Save vampaynani/89d8cfcb03819a439a6b03c3c329eb2a to your computer and use it in GitHub Desktop.
How does Redux Connect works
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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