Skip to content

Wraps the connect function from react-redux to enable passing an object in place of a mapStateToProps function.

Notifications You must be signed in to change notification settings

alsiola/redux-object-connect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redux-object-connect

This is a library that wraps the connect function from react-redux to enable passing an object in place of a mapStateToProps function.

Installation

npm install --save redux-object-connect

Usage

The original connect function requires mapStateToProps to be a function with a single argument (state), for example,

import { selector1, selector2, selector3 } from './wherever/your/selectors/are';
import { connect } from 'react-redux';

const YourComponent = ....

const mapStateToProps = state = ({
    selector1: selector1(state),
    selector2: selector2(state),
    anotherSelector: selector3(state)
});

const mapDispatchToProps = {};

export default connect(mapStateToProps, mapDispatchToProps);

redux-object-connect will take an object containing selectors and produce the appropriate function. For example, the equivalent to the above example would be:

import { selector } from './wherever/your/selector/is';
import connect from 'redux-object-connect';

const YourComponent = ....

const mapStateToProps = {
    selector1,
    selector2,
    anotherSelector: selector3
};

const mapDispatchToProps = {};

export default connect(mapStateToProps, mapDispatchToProps);

N.B. It is still possible to use the original function syntax as mapStateToProps with redux-object-connect - the result will be identical to using the react-redux connect function.

About

Wraps the connect function from react-redux to enable passing an object in place of a mapStateToProps function.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published