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.
- Host: GitHub
- URL: https://github.com/alsiola/redux-object-connect
- Owner: alsiola
- Created: 2017-01-26T20:33:32.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-27T13:23:39.000Z (over 9 years ago)
- Last Synced: 2025-02-03T23:37:11.608Z (over 1 year ago)
- Topics: mapstatetoprops, react, react-redux, redux
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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.