# react-shared-hooks

> React shared hooks

Latest version **0.0.11** (published 2018-11-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-shared-hooks
pnpm add react-shared-hooks
yarn add react-shared-hooks
bun add react-shared-hooks
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.11 |
| Published | 2018-11-26 |
| First published | 2018-11-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Dima Paloskin |
| Maintainers | paloskin |

## Links

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

## Recent versions

- 0.0.11 (latest) — 2018-11-26
- 0.0.10 — 2018-11-26
- 0.0.9 — 2018-11-26
- 0.0.8 — 2018-11-26
- 0.0.7 — 2018-11-26
- 0.0.6 — 2018-11-26
- 0.0.5 — 2018-11-11
- 0.0.4 — 2018-11-11
- 0.0.3 — 2018-11-08
- 0.0.2 — 2018-11-08
- 0.0.1 — 2018-11-08

## README

# react-shared-hooks

POC of global react hooks. Makes it possible to use global states based on hooks.

## Usage:

```js
import * as React from 'react'
import { createSharedHook, useSharedHooksState, withSharedHooks } from 'react-shared-hooks'

const { useState } = React

const counter = createSharedHook(useState, { count: 0 })

const Counter = () => {
  const [state, setState] = useSharedHooksState(state => state.counter)

  return (
    <div>
      {state.count}
      <button onClick={() => setState({ count: state.count + 1 })}>+</button>
    </div>
  )
}

const App = () => (
  <React.Fragment>
    <Counter />
    <Counter />
  </React.Fragment>
)

export default withSharedHooks({ counter })(App)

```

## API

### `createSharedHook(hook, ...args)`
- `hook`: *function* - react hook
- `...args`: *any* - arguments that will be passed at the time of the hook initialization

### `withSharedHooks(hooks)(Component)`
- `hooks`: *object* - object of created hooks
- `Component`: *React Component* - wrapped component

### `useSharedHooksState(selector)`
- `selector`: *function* - selector function that receives object of all resolved hook states

## Examples

* Simple `useState` - https://codesandbox.io/s/9zy9jwkyj4
* Inputs - https://codesandbox.io/s/kw43p7m0vr
* With `useReducer` - https://codesandbox.io/s/7yrzn42w8x

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