Array instead of mapStateToProps function in React-Redux connect
import { connect } from 'react-redux'; | |
import _ from 'lodash'; | |
export default function(...args) { | |
return function(ComponentClass) { | |
const mapStateToProps = !Array.isArray(args[0]) | |
? args[0] | |
: state => _.pick(state, args[0]); | |
return connect(mapStateToProps, mapDispatchToProps)(ComponentClass); | |
}; | |
} |
// Using this gist, just two lines: | |
import connect './connect' | |
export default connect(['persons'])(YourComponent) | |
// Using connect of react-redux directly | |
import {connect} from 'react-redux'; | |
function mapStateToProps({persons}) { | |
return {persons}; | |
} | |
export default connect(mapStateToProps)(YourComponent) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
export default connect(({persons}) => ({persons}))(YourComponent)