Skip to content

Instantly share code, notes, and snippets.



Last active Jul 24, 2018
What would you like to do?
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)

This comment has been minimized.

Copy link

@PabloMarch PabloMarch commented Jul 24, 2018

export default connect(({persons}) => ({persons}))(YourComponent)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment