# rubick-hook

> make hook-created-state shared between components

Latest version **2.0.0** (published 2020-04-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install rubick-hook
pnpm add rubick-hook
yarn add rubick-hook
bun add rubick-hook
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2020-04-30 |
| First published | 2019-11-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 8.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | corianderHunter |
| Maintainers | corianderhunter |
| Keywords | state, hook, react, proxy, redux |

## Links

- npm: https://www.npmjs.com/package/rubick-hook
- Repository: https://github.com/corianderHunter/rubick
- Homepage: https://github.com/corianderHunter/rubick#readme
- Issues: https://github.com/corianderHunter/rubick/issues
- npm.io page: https://npm.io/package/rubick-hook

## Dependencies (3)

- [react](https://npm.io/package/react.md) ^16.12.0
- [react-dom](https://npm.io/package/react-dom.md) ^16.12.0
- [@types/node](https://npm.io/package/@types/node.md) ^12.12.14

## 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.0 (latest) — 2020-04-30
- 1.0.0 — 2019-11-29

## README

# rubick

make hook-created-state shared between components

## Install

```js
npm install rubick-hook
```

## Demo

Custom Hook

```tsx
interface DustHookType {
  count: number;
  setCount: Dispatch<number>;
  ins(): void;
  des(): void;
}

export const useDust = (): DustHookType => {
  const [count, setCount] = useState<number>(0);
  const ins = () => {
    setCount(count + 1);
  };
  const des = () => {
    setCount(count - 1);
  };
  return { count, setCount, ins, des };
};

export const cacheDust = createRubickHook(useDust);
```

use in components

```tsx
const TestPart1: React.FC = () => {
  const { count, setCount, ins, des } = cacheDust();
  return (
    <div
      style={{ margin: "20px 0" }}
      onClick={() => {
        setCount(count + 1);
      }}
    >
      test-part1:{count}
    </div>
  );
};

const TestPart2: React.FC = () => {
  const { count, setCount, ins, des } = cacheDust();
  return (
    <div
      style={{ margin: "20px 0" }}
      onClick={() => {
        ins();
      }}
    >
      test-part2:{count}
    </div>
  );
};
```

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