# react-context-utilities

Latest version **2.0.7** (published 2022-02-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-context-utilities
pnpm add react-context-utilities
yarn add react-context-utilities
bun add react-context-utilities
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.7 |
| Published | 2022-02-11 |
| First published | 2019-02-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Victor Queiroz |
| Maintainers | vqueiroz |
| Keywords | react, context, productivity, utilities |

## Links

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

## 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

- 2.0.7 (latest) — 2022-02-11
- 2.0.6 — 2022-02-10
- 2.0.5 — 2022-02-10
- 2.0.4 — 2022-02-10
- 2.0.3 — 2021-05-07
- 2.0.2 — 2021-01-15
- 2.0.1 — 2021-01-15
- 2.0.0 — 2021-01-15
- 1.0.13 — 2020-08-03
- 1.0.12 — 2020-06-26
- 1.0.11 — 2020-06-08
- 1.0.10 — 2020-05-31
- 1.0.9 — 2020-05-31
- 1.0.8 — 2020-05-30
- 1.0.7 — 2020-05-28
- … 6 more at https://npm.io/package/react-context-utilities/versions

## README

# react-context-utilities

Utilities to productively create and combine new ReactJS context.

### Installation

```
yarn add react-context-utilities
```

### Usage

You can use `createSafeContext` to create a safe ReactJS context instance. Whenever you try to render the `Context.Consumer` without rendering `Context.Provider` above it, it'll throw an error. 

```ts
interface IConfig {
    maxWaitTime: number;
}
/**
 * createSafeContext will make sure it won't need to provide
 * a default value for it since it'll throw an error
 * if you try to consume without a provider above it
 */
const ConfigContext = createSafeContext<IConfig>({
    name: 'ConfigContext'
});
function mapContextToProps({ config }: { config: ConfigContext; }) {
    return {
        config
    };
}
const Menu = ({ config }: { config: IConfig; }) => {
    return <React.Fragment>
        Max response time is {config.maxWaitTime}
    </React.Fragment>;
};
/**
 * As expected, `MenuWithContext` will no longer ask
 * for `config` property in type annotation
 */
const MenuWithContext = withContext({
    config: ConfigContext
}, mapContextToProps)(Menu);
const wrapper = shallow(<ConfigContext.Provider value={{ maxWaitTime: 1000 }}>
    <MenuWithContext/>
</ConfigContext.Provider>);
```

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