# react-compose-context-consumers

> Compose React 16.3 ContextConsumers

Latest version **0.1.3** (published 2018-04-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-compose-context-consumers
pnpm add react-compose-context-consumers
yarn add react-compose-context-consumers
bun add react-compose-context-consumers
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2018-04-16 |
| First published | 2018-04-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 66.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Dibyo Majumdar |
| Maintainers | dibyo |
| Keywords | react, react16, context, ContextConsumers, compose |

## Links

- npm: https://www.npmjs.com/package/react-compose-context-consumers
- Repository: https://github.com/mDibyo/react-compose-context-consumers
- Homepage: https://github.com/mDibyo/react-compose-context-consumers#readme
- Issues: https://github.com/mDibyo/react-compose-context-consumers/issues
- npm.io page: https://npm.io/package/react-compose-context-consumers

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.1.3 (latest) — 2018-04-16
- 0.1.2 — 2018-04-16
- 0.1.1 — 2018-04-16
- 0.1.0 — 2018-04-16
- 0.0.3 — 2018-04-16

## README

# react-compose-context-consumers

Higher Order Components for composing React's `Context.Consumer`s. [See it in action!](https://codesandbox.io/s/pmy88rk640)

### Install

```bash
npm install --save react-compose-context-consumers
```

### Introduction

React 16.3 added [a new Context API](https://reactjs.org/blog/2018/03/29/react-v-16-3.html#official-context-api) -
a `Context.Provider` component (for providing the context value), and a `Context.Consumer` component (for consuming the value).
`Context.Consumer`s are added using render props.
A component might want to consume multiple contexts:
```jsx
// example copied from https://reactjs.org/docs/context.html#consuming-multiple-contexts
<ThemeContext.Consumer>
  {theme => (
    <UserContext.Consumer>
      {user => (
        <ProfilePage user={user} theme={theme} />
      )}
    </UserContext.Consumer>
  )}
</ThemeContext.Consumer>
```

This package provides a cleaner and more convenient way to compose `Context.Consumer`s:

```jsx
import Compose from 'react-compose-context-consumers';

...

<Compose theme={ThemeContext.Consumer} user={UserContext.Consumer}>
  {({ theme, user }) => (
    <ProfilePage user={user} theme={theme} />
  )}
</Compose>
```

OR

```jsx
import { compose } from 'react-compose-context-consumers';

const Composed = compose(ThemeContext.Consumer, UserContext.Consumer);

...

<Composed>
  {(theme, user) => (
    <ProfilePage user={user} theme={theme} />
  )}
</Composed>
```

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