# create-hook-context

> Create context using a hook for providers

Latest version **1.0.0** (published 2020-04-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install create-hook-context
pnpm add create-hook-context
yarn add create-hook-context
bun add create-hook-context
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-04-29 |
| First published | 2020-04-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 18.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Nikhil Saraf |
| Maintainers | nksaraf |

## Links

- npm: https://www.npmjs.com/package/create-hook-context
- Repository: https://github.com/nksaraf/create-hook-context
- npm.io page: https://npm.io/package/create-hook-context

## Recent versions

- 1.0.0 (latest) — 2020-04-29
- 0.0.6 — 2020-04-25
- 0.0.5 — 2020-04-24
- 0.0.4 — 2020-04-24
- 0.0.3 — 2020-04-19
- 0.0.2 — 2020-04-19
- 0.0.1 — 2020-04-19

## README

# create-hook-context

A more powerful version of `React.createContext`. Accepts a hook that takes in props for a provider, and then returned value of the hook, is the value provided to the context's consumers.

Signature:

```javascript

import createContext from 'create-hook-context';

const [ThemeProvider, useTheme, withThemeProvider, ThemeContext] = createContext(
  ({ theme }) => theme, // hook that provides values for context given input
  {}, // defaultValue for context
  "Theme" // displayName for Context
)

const Consumer = () => {
  const val = useTheme();
  return <pre>{JSON.stringify(val)}</pre>;
};

const App = () => {
  return (
    <ThemeProvider theme={{ a: 1 }}>
      <Consumer />
    </ThemeProvider>
  );
};

/* or can use withThemeProvider to wrap components */

const App = withThemeProvider({ theme: { a: 1 } }, () => {
  const val = useTheme();
  return <pre>{JSON.stringify(val)}</pre>;
});


```

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