An open API service indexing awesome lists of open source software.

https://github.com/alsiola/redux-object-connect

Wraps the connect function from react-redux to enable passing an object in place of a mapStateToProps function.
https://github.com/alsiola/redux-object-connect

mapstatetoprops react react-redux redux

Last synced: 27 days ago
JSON representation

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

Awesome Lists containing this project

README

          

# redux-object-connect

This is a library that wraps the connect function from [react-redux](https://github.com/reactjs/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.