# react-context-to-props

Latest version **1.0.0** (published 2016-04-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-context-to-props
pnpm add react-context-to-props
yarn add react-context-to-props
bun add react-context-to-props
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-04-02 |
| First published | 2016-04-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Joshua Thornton |
| Maintainers | jshthornton |

## Links

- npm: https://www.npmjs.com/package/react-context-to-props
- Repository: https://github.com/jshthornton/react-context-to-props
- Homepage: https://github.com/jshthornton/react-context-to-props#readme
- Issues: https://github.com/jshthornton/react-context-to-props/issues
- npm.io page: https://npm.io/package/react-context-to-props

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4.7.0

## Recent versions

- 1.0.0 (latest) — 2016-04-02

## README

# react-context-to-props

`npm i --save react-context-to-props`

I love react, you love react, but the bit I am still not 100% happy with is the redux-react bindings.
My biggest gripe is the lack of being able to use contexts in mapped dispatches.

To compensate for this we have `react-context-to-props`. This is a higher order components that will automatically place
contexts that you desire into a components props. That way, you can use it with redux-react's connect HOC.

## Usage

### Basic
```
import { connect } from 'react-redux';
import React, { Component } from 'react';
import ContextToProps from 'react-context-to-props';

const mapStateToProps = (state, ownProps) => {
  return {
  };
}

const mapDispatchToProps = (dispatch, ownProps) => {
  return {
    onFoo: function(data) {
      ownProps.router.push(`/foo`);
    }
  };
}

export default ContextToProps({
  router: React.PropTypes.object
})(connect(mapStateToProps, mapDispatchToProps)(Component));
```

### Advanced

Sometimes you do not want the original key name to be used when passed as a prop.
react-context-to-props allows you to provide a mapping function.

```
import { connect } from 'react-redux';
import React, { Component } from 'react';
import ContextToProps from 'react-context-to-props';

const mapStateToProps = (state, ownProps) => {
  return {
  };
}

const mapDispatchToProps = (dispatch, ownProps) => {
  return {
    onFoo: function(data) {
      ownProps.myRouter.push(`/foo`);
    }
  };
}

export default ContextToProps({
  router: React.PropTypes.object
}, {
  myRouter: router
})(connect(mapStateToProps, mapDispatchToProps)(Component));
```

---
_Source: https://npm.io/package/react-context-to-props · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
