# react-safe-context-hooks

> Make sure context exists

Latest version **1.0.1** (published 2021-04-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-safe-context-hooks
pnpm add react-safe-context-hooks
yarn add react-safe-context-hooks
bun add react-safe-context-hooks
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2021-04-03 |
| First published | 2020-09-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jakub Biesiada |
| Maintainers | jbiesiada |
| Keywords | react, hooks, context, api, error, exists, confidence |

## Links

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

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2021-04-03
- 1.0.0-beta.0 (beta) — 2020-11-10
- 1.0.0 — 2020-12-24
- 0.0.0 — 2020-09-26

## README

# [react-safe-context-hooks](https://github.com/cool-hooks/react-safe-context-hooks)

[![NPM version](https://img.shields.io/npm/v/react-safe-context-hooks?style=flat-square)](https://www.npmjs.com/package/react-safe-context-hooks)
[![NPM downloads](https://img.shields.io/npm/dm/react-safe-context-hooks?style=flat-square)](https://www.npmjs.com/package/react-safe-context-hooks)
[![NPM license](https://img.shields.io/npm/l/react-safe-context-hooks?style=flat-square)](https://www.npmjs.com/package/react-safe-context-hooks)
[![Codecov](https://img.shields.io/codecov/c/github/cool-hooks/react-safe-context-hooks?style=flat-square)](https://codecov.io/gh/cool-hooks/react-safe-context-hooks)
[![Travis](https://img.shields.io/travis/cool-hooks/react-safe-context-hooks/master?style=flat-square)](https://travis-ci.org/cool-hooks/react-safe-context-hooks)
[![Bundle size](https://img.shields.io/bundlephobia/min/react-safe-context-hooks?style=flat-square)](https://bundlephobia.com/result?p=react-safe-context-hooks)

## About

Make sure context exists

### Demo

**[Playground – play with library in CodeSandbox](https://codesandbox.io/s/react-safe-context-hooks-6me74)**

### Similar Projects

- [react-safe-context](https://github.com/dslane/react-safe-context) by [dslane](https://github.com/dslane)

## How to Install

First, install the library in your project by npm:

```sh
$ npm install react-safe-context-hooks
```

Or Yarn:

```sh
$ yarn add react-safe-context-hooks
```

## Getting Started

**• Import hook in React application file:**

```js
import { useSafeContext } from 'react-safe-context-hooks';
```

**If you want to display context name in error message you need to add `displayName` to `Context`.**

### Example

```js
// before
const App = () => {
  const context = useContext(ExampleContext);

  return <pre>{JSON.stringify(context)}</pre>;
};

// after
ExampleContext.displayName = 'ExampleContext';

const App = () => {
  const context = useSafeContext(ExampleContext);

  return <pre>{JSON.stringify(context)}</pre>;
};
```

## License

This project is licensed under the MIT License © 2020-present Jakub Biesiada

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